This is a REST API that allows authenticated users to rate a menu item and view the available ratings.
Check the requirements.txt file for the required dependencies.
- Clone the repository:
git clone https://github.com/Ibrahim-mj/RatingAPI.git
- Create a virtual environment:
python -m venv .venv
- Activate the virtual environment:
- Install the requirements:
pip install -r requirements.txt
- Run the migrations:
python manage.py migrate
- Run the server:
python manage.py runserver
- Open the browser and go to the local server address
- Create a rating:
POST /api/ratings/
Request body:
{
"menu_id": 1,
"rating": 5
}
Response body:
{
"id": 1,
"menu_id": 1,
"rating": 5,
"user": 1
}
This endpoint uses Djoser's Token Authentication. To get a token, you must register a user and then login. The token is returned in the response body.
- Register a user:
POST /auth/users/
Request body:
{
"username": "username",
"password": "password"
}
Response body:
{
"email": "",
"username": "username",
"id": 1
}
- Login:
POST /auth/token/login/
Request body:
{
"username": "username",
"password": "password"
}
Response body:
{
"auth_token": "token"
}
- Get all ratings:
GET /api/ratings/
Response body:
[
{
"id": 1,
"menu_id": 1,
"rating": 5,
"user": 1
},
{
"id": 2,
"menu_id": 1,
"rating": 4,
"user": 2
}
]
- Get a rating:
GET /api/ratings/<id>/
Response body:
{
"id": 1,
"menu_id": 1,
"rating": 5,
"user": 1
}