Trong bài này bạn sẽ vận dung kiến thức ở hai bài vừa học (GET – POST) để thực hành trên Postman dựa vào thông tin yêu cầu như bên dưới. Các bạn cần đọc kĩ yêu cầu để biết được ý nghĩa của các API cũng như các trường cần thiết.

1. Get an employee by ID

This API will retrieving one employee by the employee_id, the response data will show all details of that ID.

URL https://sangbui.com/api/v1/employees/<employee_id>
Method GET
URL Params <employee_id>
Header Content-Type: application/json

Authorization: Basic d2ViX2FwcDpjaGFuZ2VpdA==

Data Params <none>
Success Response Code: 200 OK

Content:

[

{

“id”: “<id>”,

“employee_name”: “<name>”,

“employee_salary”: “<salary>”,

“employee_age”: “<age>”

}

]

Error Response 401 Unauthorized (Incorrect permission)
Sample Call http://localhost/employee_api/v1/employees/1
Notes In our database, the employee_id from 1 to 15 will be stable and will not removed, so you can use these IDs for testing and get the sample data.

 

2. Update an employee information

This API will help to update an employee information by the employee_id.

URL https://sangbui.com/api/v1/employees
Method PUT
URL Params <none>
Header Content-Type: application/json

Authorization: Basic d2ViX2FwcDpjaGFuZ2VpdA==

Data Params {

“id”: “<id>”,

“employee_name”: “<new_name>”,

“employee_salary”: “<new_salary>”,

“employee_age”: “<new_age>”

}

 

Success Response Code: 200 OK

Content:

{

“status”: 1,

“status_message”: “Employee updated successfully.”

}

 

Error Response 401 Unauthorized (Incorrect permission)
Sample Call {

“id” : 7,

“employee_name” : “Nam”,

“employee_salary”: “800”,

“employee_age”: “25”

}

Notes <none>

 

3. Delete an employee

This API will support to delete an employee by the employee_id.

URL https://sangbui.com/api/v1/employees
Method DELETE
URL Params <none>
Header Content-Type: application/json

Authorization: Basic d2ViX2FwcDpjaGFuZ2VpdA==

Data Params {

“id” : <id>

}

Success Response Code: 200 OK

Content:

{

“status”: 1,

“status_message”: “Employee deleted successfully.”

}

 

Error Response 401 Unauthorized (Incorrect permission)
Sample Call {

“id” : 5

}

Notes <none>

 

2 Comments

Leave a Comment

Your email address will not be published.