A simple Django REST API
The solution has been deployed to Heroku:
You can find it here.
SSYS team is growing every month and now we need to have some application to manage employee's information and reports. As any application written at SSYS, it must have an API to allow integrations.
-
API with employees CRUD:
- GET: /employees/ (employee list)
- POST: /employees/ (employee create)
- UPDATE /employees/ID/ (employee update)
- DELETE /employees/ID/ (employee delete)
- GET /employees/ID/ (employee detail)
-
API with reports:
- GET /reports/employees/salary/ (salary report)
- GET /reports/employees/age/ (age report)
-
Persist data in a database
-
Use authentication to access
Request:
curl -H "Content-Type: application/json" localhost:8000/employees/
Response:
[
{
"id": "1",
"name": "Anakin Skywalker",
"email": "[email protected]",
"department": "Architecture",
"salary": "4000.00",
"birth_date": "01-01-1983"},
{
"id": "2",
"name": "Obi-Wan Kenobi",
"email": "[email protected]",
"department": "Back-End",
"salary": "3000.00",
"birth_date": "01-01-1977"},
{
"id": "3",
"name": "Leia Organa",
"email": "[email protected]",
"department": "DevOps",
"salary": "5000.00",
"birth_date": "01-01-1980"
}
]
Request:
curl -H 'Content-Type: application/json' localhost:8000/reports/employees/age/
Response:
{
"younger": {
"id": "1",
"name": "Anakin Skywalker",
"email": "[email protected]",
"department": "Architecture",
"salary": "4000.00",
"birth_date": "01-01-1983"},
"older": {
"id": "2",
"name": "Obi-Wan Kenobi",
"email": "[email protected]",
"department": "Back-End",
"salary": "3000.00",
"birth_date": "01-01-1977"},
"average": "40.00"
}
Request:
curl -H 'Content-Type: application/json' localhost:8000/reports/employees/salary/
Response:
{
"lowest ": {
"id": "2",
"name": "Obi-Wan Kenobi",
"email": "[email protected]",
"department": "Back-End",
"salary": "3000.00",
"birth_date": "01-01-1977"},
"highest": {
"id": "3",
"name": "Leia Organa",
"email": "[email protected]",
"department": "DevOps",
"salary": "5000.00",
"birth_date": "01-01-1980"},
"average": "4000.00"
}