This guide explains how to test API endpoints using Postman. The API supports CRUD (Create, Read, Update, Delete) operations on a dataset.
Created by: Ashish kumar | github: https://github.com/ashishkumar30
π The logger is activated in this setup. Please check the logs in the logfile at logs/gloroots_app.log
βββ app_crud_operations
β βββ __init__.py
β βββ admin.py
β βββ apps.py
β βββ crud_controller.py
β βββ migrations
β βββ models.py
β βββ response_json.py
β βββ serializers.py
β βββ tests.py
β βββ urls.py
β βββ views.py
βββ db.sqlite3
βββ gloroots
β βββ __init__.py
β βββ asgi.py
β βββ settings.py
β βββ urls.py
β βββ wsgi.py
βββ logs
β βββ gloroots_app
β βββ gloroots_app.log
βββ manage.py
βββ test.py
python -m venv venv # Create a virtual environment
source venv/bin/activate # Activate on macOS/Linux
venv\Scripts\activate # Activate on Windows
pip install -r requirements.txt
python manage.py runserver 8000
python test.py
Alternatively, you can manually test endpoints using Postman.
- Install Postman
- Ensure the API server is running at
http://127.0.0.1:8000
- URL:
http://127.0.0.1:8000
- Method:
POST
- Headers:
Content-Type
:application/json
unloc
:unlocs
- Body: Raw JSON from GitHub Data
{
"AEAJM": {
"name": "Ajman",
"city": "Ajman",
"country": "United Arab Emirates",
"coordinates": [55.5136433, 25.4052165],
"province": "Ajman",
"timezone": "Asia/Dubai",
"unlocs": ["AEAJM"],
"code": "52000"
}
}
{
"Status_code": 201,
"Status": "Success",
"Message": "New Data Created",
"Data": [{
"un_location_code_id": "AEAJM",
"name": "Ajman",
"city": "Ajman",
"country": "United Arab Emirates",
"coordinates": [55.5136433, 25.4052165],
"province": "Ajman",
"timezone": "Asia/Dubai",
"code": "52000",
"unlocs": ["AEAJM"]
}]
}
- URL:
http://127.0.0.1:8000?unloc=AOSZA
- Method:
GET
- Headers:
Content-Type
:application/json
unloc
:XLDSSS
{
"XLDSSS": {
"name": "ASHISH",
"city": "ASHISH",
"country": "United Arab Emirates",
"coordinates": [55.5136433, 25.4052165],
"province": "Ajman",
"timezone": "Asia/Dubai",
"unlocs": ["AEAJM"],
"code": "52000"
}
}
- Response: Returns requested data based on
unloc
in headers. - Response: Returns all data if
unloc
is not passed.
- URL:
http://127.0.0.1:8000?unloc=AEDXB
- Method:
PATCH
- Headers:
Content-Type
:application/json
unloc
:AEDXB
{
"AEDXB": {
"name": "ASHISH",
"city": "ASHISH",
"country": "United Arab Emirates",
"coordinates": [55.5136433, 25.4052165],
"province": "Ajman",
"timezone": "Asia/Dubai",
"unlocs": ["AEAJM"],
"code": "52000"
}
}
{
"Status_code": 201,
"Status": "Success",
"Message": "Data inserted successfully",
"Data": {
"un_location_code_id": "AEDXB",
"name": "ASHISH",
"city": "ASHISH",
"country": "United Arab Emirates",
"coordinates": [55.5136433, 25.4052165],
"province": "Ajman",
"timezone": "Asia/Dubai",
"code": "52000",
"unlocs": ["AEAJM"]
}
}
- URL:
http://127.0.0.1:8000?unloc=ESCAR
- Method:
DELETE
- Headers:
unloc
:AEDXB
{
"Status_code": 204,
"Status": "Success",
"Message": "Location with UN location 'ESCAR' deleted successfully",
"Data": null
}