This is a simple REST API built with Python and FastAPI and SQLAlchemy for CRUD operations (Create, Read, Update, Delete) on users. FastAPI is a powerful web framework for building APIs.
Clone this repository to your local machine:
git clone https://github.com/BaseMax/SimpleFastPyAPI
Change into the project directory:
cd SimpleFastPyAPI
Install the project dependencies:
pip install -r requirements.txt
Run the application:
uvicorn main:app --reload
The application will start and be available at https://localhost:8000.
GET /users
Returns a list of all users in the system:
curl https://localhost:8000/users/ -H "Accept: application/json"
Response:
[
{
"email": "[email protected]",
"id": 1,
"password": "password1",
"name": "Alice"
},
{
"email": "[email protected]",
"id": 2,
"password": "password2",
"name": "Bob"
},
{
"email": "[email protected]",
"id": 3,
"password": "password3",
"name": "Charlie"
}
]
GET /users/{user_id}
Returns details for a specific user with the given user_id:
curl https://localhost:8000/users/1 -H "Accept: application/json"
Response:
{
"email": "[email protected]",
"id": 1,
"password": "password1",
"name": "Alice"
}
POST /users
Adds a new user to the system. The request body should include a JSON object with the following properties:
name
(string, required): the name of the useremail
(string, required): the email address of the userpassword
(string, required): the password for the user
curl -X POST https://localhost:8000/users/
-H 'Content-Type: application/json'
-d '{"name":"Ali","password":"123456", "email": "[email protected]"}'
Response:
{
"email": "[email protected]",
"password": "123456",
"id": 4,
"name": "Ali"
}
PUT /users/{user_id}
Updates an existing user with the given user_id. The request body should include a JSON object with the following properties:
name
(string): the new name for the useremail
(string): the new email address for the user
curl -X PUT https://localhost:8000/users/1
-H "Accept: application/json"
-d '{"name": "Reza", "email": "[email protected]"}'
Response:
{"message": "User updated successfully"}
DELETE /users/{user_id}
Deletes the user with the given user_id:
curl -X DELETE https://localhost:8000/2
Response:
{"message": "User deleted successfully"}
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.
Copyright 2023, Max Base