A simple example of using RestAPi on Django
git clone https://github.com/ZeroNiki/Django-RestAPI-Example.git
cd Django-RestAPI-Example
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
cd app
python3 manage.py makemigrations # if necessary
python3 manage.py migrate
python3 manage.py createsuperuser # create user for admin panel
python3 manage.py runserver # go to http://127.0.0.1:8000
/
- Django API root
/admin
- admin panel
get all data:
curl --header "Content-Type: application/json" \
--request GET \
--url "http://127.0.0.1:8000/api/todo/"
Add data:
curl --header "Content-Type: application/json" \
--request POST \
--data '{"title": "Test Todo"}' \
http://127.0.0.1:8000/api/todo/
Update data:
curl --header "Content-Type: application/json" \
--request PUT \
--data '{"title": "Update test Todo"}' \
http://127.0.0.1:8000/api/todo/{id}
Delete data:
curl --request DELETE http://127.0.0.1:8000/api/todo/{id}