Luizalabs' team is growing every month and now we need to have some application to manage employees' information, such as name, e-mail and department. As any application written at Luizalabs, it must have an API to allow integrations
Using Python 3.6 and framework Django was created an solution with REST API and Django Admin.
Considering python3 and pip is already installed, we should use these bellow step:
- git clone repository url
- go to project directory
- pip install -r requirements.txt
- python manage.py createsuperuser
- Here we will make an user to access administration site. (already created)
- Login: admin
- Password: admin
- python manage.py runserver
- Open an browser and go to http://localhost:8000.
- Insert login and password registered on instalation guide (admin/admin).
- Get all employees
GET : /employee/
- Get employee
GET : /employee/<id>/
- Add employee
POST : /employee/
- Delete employee
DELETE : /employee/<id>/
- Update employee
PUT : /employee/<id>/
- Get Access Token
GET : /api/token/
- Refresh Access Token
GET : /api/token/refresh/
example: http://localhost:8000/employee/
For Delete and PUT methods you should have a token.
-
department tags
"E" for E-commerce
,"M" for Mobile
and"A" for Architeture
. -
getting a token :
curl -X POST -d "username=<username>&password=<password>" http://localhost:8000/api/token/
-
refreshing a token:
curl -X POST -H "Content-Type: application/json" -d '{"refresh":"<access-token>"}' http://localhost:8000/api/token/refresh/
-
get all employees:
curl -X GET -H "Content-Type: application/javascript" http://localhost:8000/employee/
-
get an employee :
curl -X GET -H "Content-Type: application/javascript" http://localhost:8000/employee/<id-employee>/
-
create employee :
curl -X POST http://localhost:8000/employee/ -H "Content-Type: application/json" -d '{"name": "<name>", "email": "<email>", "department": "<department tag>"}'
-
delete an employee :
curl -X DELETE -H "Authorization: Bearer <access-token>" -H "Content-Type: application/javascript" http://localhost:8000/employee/<id-employee>/
-
update an employee :
curl -X PUT -H "Authorization: Bearer <access-token>" http://localhost:8000/employee/<id-employee>/ -H "Content-Type: application/json" -d '{"name": "<name>", "email": "<email>", "department": "<department-tag>"}'