A command-line CRUD application built with Python, Requests, and MockAPI.
This project was created to practice working with REST APIs, HTTP methods, JSON data, input validation, exception handling, and CRUD operations from a Python command-line application.
- View all users
- View a single user by ID
- Create a new user
- Update an existing user
- Delete a user
- Input validation
- API request timeout handling
- Connection error handling
- HTTP error handling
- Environment variable configuration
- Interactive command-line menu
- Python
- Requests
- python-dotenv
- REST API
- MockAPI
- JSON
- Git & GitHub
user-api-cli/
│
├── app.py
├── validation.py
├── README.md
├── requirements.txt
├── .gitignore
└── screenshots/
Contains the main application logic and API CRUD operations:
- GET all users
- GET one user
- POST user
- PUT user
- DELETE user
- Main menu
Contains reusable input-validation functions:
- User ID validation
- Name validation
- Phone validation
- Email validation
- API error handling
The project uses a MockAPI REST API.
| Method | Endpoint | Description |
|---|---|---|
| GET | /users |
Get all users |
| GET | /users/{id} |
Get one user |
| POST | /users |
Create a user |
| PUT | /users/{id} |
Update a user |
| DELETE | /users/{id} |
Delete a user |
git clone https://github.com/naved2001/user-api-cli
### 2. Open the project
```bash
cd user-api-cliWindows:
python -m venv venvPowerShell:
venv\Scripts\Activate.ps1Command Prompt:
venv\Scripts\activatepip install -r requirements.txtCreate a .env file in the project root.
API_KEY=your_mockapi_project_idDo not upload .env to GitHub.
python app.pyYou will see:
---===--- USER API ---===---
1. Show All Users
2. Show One User
3. Create User
4. Update User
5. Delete User
6. Exit
Enter your choice:
Displays all users stored in the MockAPI endpoint.
ID: 1 | Name: Mohammad Naved | Phone: 9876543210 | Email: naved@example.com
Enter a user ID to retrieve a specific user.
Enter ID: 1
ID: 1
Name: Mohammad Naved
Phone: 9876543210
Email: naved@example.com
The application asks for:
- Name
- Phone number
The information is sent to MockAPI using a POST request.
The application checks whether the user exists and then sends updated information using a PUT request.
The application checks whether the user exists and then removes the user using a DELETE request.
Through this project, I practiced:
- Python functions
- Input validation
- Loops and conditional statements
- Dictionaries
- Exception handling
- Environment variables
- HTTP requests
- REST API concepts
- JSON data
- CRUD operations
- GET, POST, PUT, and DELETE methods
- Request timeouts
- HTTP status codes
- Separating validation logic from application logic
CREATE → POST
READ → GET
UPDATE → PUT
DELETE → DELETE
The application handles common request errors including:
- Request timeout
- Connection failure
- HTTP errors
- General request errors
This project uses MockAPI as a mock backend for learning and development purposes.
The application demonstrates how a Python client communicates with a REST API. It is not intended to be a production user-management system.
Mohammad Naved
Full Stack Web Developer
- GitHub:
naved2001 - LinkedIn:
mohammad-naved-ansari
Possible future improvements:
- Add search functionality
- Add pagination
- Improve email validation
- Add logging
- Add unit tests
- Add API service layer
- Add authentication
- Add configuration management
- Convert the CLI application into a Django/REST backend
- Build a React frontend for the API
If you find this project useful for learning, feel free to explore the code and experiment with the API.
