This project is a simple Django application that provides CRUD operations for users and includes an authentication system using Django REST Framework (DRF) and Token Authentication.
- Python 3.x
- asgiref==3.8.1
- Django==5.1
- djangorestframework==3.15.2
- sqlparse==0.5.1
- tzdata==2024.1
-
Clone the Repository
git clone https://github.com/MrMaximeliom/SimpleApi.git cd SimpleApi
-
Clone the Repository
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install Dependencies
pip install -r requirements.txt
-
Apply Migrations
python manage.py makemigrations python manage.py migrate
-
Create a Superuser (optional)
python manage.py createsuperuser
Start the Django development server:
python manage.py runserver
The server will start at http://127.0.0.1:8000/.
- Endpoint:
/api/users/
- Method: POST
- Description: Registers a new user.
- Request Body:
{
"username": "your_username",
"email": "your_email@example.com",
"name": "Your Name",
"password": "your_password"
}
- Response
{
"id": 1,
"username": "your_username",
"email": "your_email@example.com",
"name": "Your Name"
}
- Endpoint:
/api/auth/login/
- Method: POST
- Description: Authenticates a user and returns an authentication token.
- Request Body:
{
"username": "your_username",
"password": "your_password"
}
- Response
{
"token": "your_auth_token",
"user_id": 1,
"username": "your_username"
}
- Endpoint:
/api/users/<id>/
- Method: GET
- Description: Retrieves the details of a specific user by ID.
- Response:
{
"id": 1,
"username": "your_username",
"email": "your_email@example.com",
"name": "Your Name"
}
- Endpoint:
/api/users/<id>/
- Method: PUT
- Description: Updates a specific user's details.
- Request Body: (password is optional)
{
"username": "new_username",
"email": "new_email@example.com",
"name": "New Name",
"password": "new_password"
}
- Response
{
"id": 1,
"username": "new_username",
"email": "new_email@example.com",
"name": "New Name"
}
- Endpoint:
/api/users/<id>/
- Method: DELETE
- Description: Deletes a specific user by ID.
- Response:HTTP 204 No Content.
The API uses token-based authentication. After a successful login,
include the token in the Authorization
header for subsequent requests:
Authorization: Token your_auth_token
curl -H "Authorization: Token your_auth_token" http://127.0.0.1:8000/api/users/
This will authenticate the request using the provided token.