An API to keep track of calories consumed by user.
An API to keep track of daily calories consumed by user. Also users can set their daily maximum calorie consumption limit. Once this limit exceeds, every food-item consumed thereafter shall have a boolean field set to True for calories_exceeded field.
$ git clone https://github.com/suvhotta/calorie_app_DRF.git
$ cd calorie-tracker-django-restframework
$ pipenv install
$ pipenv shell
$ python manage.py makemigrations
$ python manage.py migrate
$ python manage.py runserver
To create an admin with default username: admin, password: admin, and max_calories: 2000
$ python manage.py create_admin
To specify the username, password or max_calories:
$ python manage.py create_admin --username <username>
--password <password> --max_calories <max_calories>
The admin account can be therafter used to create more users.
There isn’t any limitation on username and password, however the max_calories should be an integer.
In a RESTful API, endpoints (URLs) define the structure of the API and how end users access data from our application using the HTTP methods - GET, POST, PATCH, PUT, DELETE.
Endpoint | HTTP Method | CRUD | RESULT |
---|---|---|---|
register | POST | CREATE | creates new user |
users | GET | READ | list of all users |
users/pk | GET | READ | Single User info |
users/pk | PUT | UPDATE | Updates a user |
users/pk | PATCH | UPDATE | Updates a user |
users/pk | DELETE | DELETE | Deletes a user |
fooditem | POST | CREATE | Creates a food entry |
fooditem | GET | READ | List of all fooditems |
fooditem/pk | GET | READ | Details about a particular food entry |
fooditem/pk | PUT | UPDATE | Updates a food entry |
fooditem/pk | PATCH | UPDATE | Updates a food entry |
fooditem/pk | DELETE | DELETE | Deletes a food entry |
login | POST | CREATE | Creates a token for user login |
Login:
The token key thus generated can be passed to the authentication header while accessing other api end-points.
User Registration:
Adding Food-item:
Filters: