Address Book api developed in django using rest framework library.
$ git clone https://github.com/kenvac/qogita-address-book-api
$ pip install -r requirements.txt
$ python manage.py makemigrations
$ python manage.py migrate
$ python manage.py runserver
Use the following commands to create super users in the system
$ python manage.py createsuperuser --username=example1 --email=example1@example.com
User needs to login to perform any kind of requests. The login use email and password fields of user.
POST http://{url}/api/login
Header | Value |
---|---|
Content-Type | application/json |
In the request body, supply a JSON representation of an items object.
If successful, this method returns 200 ok response code and an items object in the response body
Request Here is an example of a request
POST http://{url}/api/login
Content-type: application/json
{
"auth_token": "ff2fff6508a17423f6320a824d3c795dabba6271"
}
Any current session will expire and client will require to login to perform any new requests.
POST http://{url}/api/logout
Header | Value |
---|---|
Authorization | Token {token_value} |
Content-Type | application/json |
In the request body, supply a JSON representation of an items object.
If successful, this method returns 204 No Content response code
Request Here is an example of a request
POST http://{url}/api/logout
Content-type: application/json
{}
Create an address using api. Note: Duplicate address with same name, street and zip are not allowed
POST http://{url}/api/addressbook
Header | Value |
---|---|
Authorization | Token {token_value} |
Content-Type | application/json |
In the request body, supply a JSON representation of an items object.
If successful, this method returns 201 Created response code and returns the item in the response body
Here is an example of a request.
POST http://{url}/api/addressbook
Content-type: application/json
{
"name": "Home",
"street": "6 Cannon",
"street2": "street2",
"zip": "380061",
"country": "GB"
}
Here is an example of the response.
{
"status": "success",
"data": {
"id": 7,
"street2": "street2",
"city": "",
"state": "",
"country": {
"code": "GB",
"name": "United Kingdom"
},
"phone_number": "",
"email": "",
"name": "Home",
"street": "6 Cannon",
"zip": "380061",
"owner": 1
}
}
Fetch addresses api
Get all addresses from database
GET http://{url}/api/addressbook
Get an address with database id
GET http://{url}/api/addressbook/{id}
Filter address using zip code
GET http://{url}/api/addressbook?zip={value}
Header | Value |
---|---|
Authorization | Token {token_value} |
Content-Type | application/json |
In the request body, supply a JSON representation of an items object.
If successful, this method returns 200 OK response code and returns the item in the response body
Here is an example of a request.
GET http://{url}/api/addressbook/{id}
Content-type: application/json
Here is an example of the response.
{
"status": "success",
"data": {
"id": 7,
"street2": "street2",
"city": "",
"state": "",
"country": {
"code": "GB",
"name": "United Kingdom"
},
"phone_number": "",
"email": "",
"name": "Home",
"street": "6 Cannon",
"zip": "380061",
"owner": 1
}
}
Update an address api
PATCH http://{url}/api/addressbook/{id}
Header | Value |
---|---|
Authorization | Token {token_value} |
Content-Type | application/json |
In the request body, supply a JSON representation of an items object.
If successful, this method returns 200 OK response code and returns the item in the response body
Here is an example of a request.
PATCH http://{url}/api/addressbook/{id}
Content-type: application/json
{
"city": "Rugby",
"phone_number": "1234567"
}
Here is an example of the response.
{
"status": "success",
"data": {
"id": 6,
"street2": "street2street",
"city": "Rugby",
"state": "",
"country": {
"code": "GB",
"name": "United Kingdom"
},
"phone_number": "1234567",
"email": "",
"name": "Kinner",
"street": "street1",
"zip": "380061",
"owner": 1
}
}
Delete addresses api
Delete single record using id
DELETE http://{url}/api/addressbook/{id}
Batch delete addresses
POST http://{url}/api/addressbook/batchdelete
{
"ids": {list_ids}
}
Header | Value |
---|---|
Authorization | Token {token_value} |
Content-Type | application/json |
In the request body, supply a JSON representation of an items object.
If successful, this method returns 200 OK response code and returns the item in the response body
Here is an example of a request.
POST http://{url}/api/addressbook/batchdelete
Content-type: application/json
{
"ids": [7,8]
}
Here is an example of the response.
{
"status": "success",
"reason": "Addresses Deleted",
"data": {
"ids": [7,8],
}
}
Here is an example of a request.
DELETE http://{url}/api/addressbook/{id}
Content-type: application/json
Here is an example of the response.
{
"status": "success",
"data": "Address Deleted"
}