API for creating, reading, updating and deleting customers and their favorite products
$ git clone https://github.com/lsantosdemoura/customers-API.git
$ cd customers-API
# You can build and start docker at once
$ docker-compose up --build
- The project itself:
$ docker-compose exec web bash
- Postgres:
$ docker-compose exec db bash
$ cd customers-API
$ docker-compose -f test.yml build
$ docker-compose -f test.yml run test_api
$ python manage.py createsuperuser --username test --email [email protected]
$ python manage.py drf_create_token test
Generated token 9c474c3d334a6b073b62cc76622a60fb4d19464f for user test
$ http http://localhost:8000/api/favorites/ 'Authorization: Token 9c474c3d334a6b073b62cc76622a60fb4d19464f'
HTTP/1.1 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Length: 522
Content-Type: application/json
Date: Tue, 10 Sep 2019 16:13:28 GMT
Server: WSGIServer/0.2 CPython/3.7.4
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN
[
{
"customer": "[email protected]",
"product_id": "1bf0f365-fbdd-4e21-9786-da459d78dd1f",
"url": "http://localhost:8000/api/favorites/1/"
},
{
"customer": "[email protected]",
"product_id": "571fa8cc-2ee7-5ab4-b388-06d55fd8ab2f",
"url": "http://localhost:8000/api/favorites/2/"
},
{
"customer": "[email protected]",
"product_id": "f6c094e1-f27d-677b-4187-cf6a5acd03aa",
"url": "http://localhost:8000/api/favorites/3/"
},
{
"customer": "[email protected]",
"product_id": "f6c094e1-f27d-677b-4187-cf6a5acd03aa",
"url": "http://localhost:8000/api/favorites/7/"
}
]
$ http http://localhost:8000/api/favorites/
HTTP/1.1 401 Unauthorized
Allow: GET, POST, HEAD, OPTIONS
Content-Length: 58
Content-Type: application/json
Date: Tue, 10 Sep 2019 16:14:44 GMT
Server: WSGIServer/0.2 CPython/3.7.4
Vary: Accept, Cookie
WWW-Authenticate: Basic realm="api"
X-Frame-Options: SAMEORIGIN
{
"detail": "Authentication credentials were not provided."
}
http post http://127.0.0.1:8000/api-token-auth/ username=test password=test123
HTTP/1.1 200 OK
Allow: POST, OPTIONS
Content-Length: 52
Content-Type: application/json
Date: Tue, 10 Sep 2019 16:17:25 GMT
Server: WSGIServer/0.2 CPython/3.7.4
Vary: Cookie
X-Frame-Options: SAMEORIGIN
{
"token": "9c474c3d334a6b073b62cc76622a60fb4d19464f"
}
http post http://127.0.0.1:8000/customers/ name:='"test5"' email:='"[email protected]"' 'Authorization: Token 9c474c3d334a6b073b62cc76622a60fb4d19464f'
HTTP/1.1 201 Created
Allow: GET, POST, HEAD, OPTIONS
Content-Length: 90
Content-Type: application/json
Date: Tue, 10 Sep 2019 16:26:00 GMT
Server: WSGIServer/0.2 CPython/3.7.4
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN
{
"email": "[email protected]",
"name": "test5",
"url": "http://127.0.0.1:8000/api/customers/8/"
}
You can also delete, list, and patch a Customer
http post http://127.0.0.1:8000/favorites/ customer_email:='"[email protected]"' product_id:='"f8cb4a82-910e-6654-1240-d994c2997d2c"' 'Authorization: Token 9c474c3d334a6b073b62cc76622a60fb4d19464f'
HTTP/1.1 201 Created
Allow: GET, POST, HEAD, OPTIONS
Content-Length: 129
Content-Type: application/json
Date: Tue, 10 Sep 2019 16:31:06 GMT
Server: WSGIServer/0.2 CPython/3.7.4
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN
{
"customer": "[email protected]",
"product_id": "f8cb4a82-910e-6654-1240-d994c2997d2c",
"url": "http://127.0.0.1:8000/api/favorites/9/"
}
http http://127.0.0.1:8000/api/customers/8/ 'Authorization: Token 9c474c3d334a6b073b62cc76622a60fb4d19464f'
HTTP/1.1 200 OK
Allow: GET, PATCH, DELETE, HEAD, OPTIONS
Content-Length: 627
Content-Type: application/json
Date: Tue, 10 Sep 2019 16:32:33 GMT
Server: WSGIServer/0.2 CPython/3.7.4
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN
{
"email": "[email protected]",
"favorites": [
{
"image": "http://challenge-api.luizalabs.com/images/f8cb4a82-910e-6654-1240-d994c2997d2c.jpg",
"price": 667.8,
"product_id": "f8cb4a82-910e-6654-1240-d994c2997d2c",
"reviewScore": null,
"title": "Cadeira para Auto Burigotto Matrix p/ Crianças",
"url": "http://127.0.0.1:8000/api/favorites/8/"
},
],
"name": "test5"
}