Example of simple django project with API
Install all dependency:
- django == 3.2.7
- djangorestframework == 3.12.4
$ pip install -r requirements.txt
$ python manage.py runserver 0.0.0.0:8000
Database hold data for 2020 year
Open your browser and enter http://0.0.0.0:8000/
$ curl "http://127.0.0.1:8000/api/"
All endpoint:
/api/
/api/users/
/api/consumption/
/api/month-consumption/
/api/month-consumption/
should contain body data or GET request parameters
Example:
# With GET request parameters
$ curl "http://127.0.0.1:8000/api/month-consumption/?name=John&date=2020-09-24"
# With body data
$ curl --header "Content-Type: application/json" \
--request GET \
--data '{"name": "Bob", "date": "2020-09-23"}' \
http://127.0.0.1:8000/api/month-consumption/
Install dev dependency
$ pip install -r requirements-dev.txt
And run
$ pytest
This project is licensed under the terms of the MIT license.