Các câu hỏi liên quan đến restful API
Một câu hỏi khá đơn giản trong quá trình phỏng vấn là
1- What is restful API
với câu hỏi này bạn nên có 3 ý chính :
1.1 - Nó là 1 API (application program interface)
1.2 - Nó hoạt động dựa trên HTTP
1.3- Nó cung cấp các method để thao tác với dữ liệu gồm GET, POST, PUT, DELETE
2 - Khác nhau giữa PUT và Patch
PUT : update if exist id, or create new
Patch : Update if exist id or throw an exception
3 - Json standard in Restful API
3.1 Use nouns instead of verbs in endpoint paths
3.2 Use logical nesting on endpoints
/articles
/article/id/comments
3.4 - Handle errors gracefully and return standard error codes
Common error HTTP status codes include:
400 Bad Request – This means that client-side input fails validation.
401 Unauthorized – This means the user isn’t not authorized to access a resource. It usually returns when the user isn’t authenticated.
403 Forbidden – This means the user is authenticated, but it’s not allowed to access a resource.
404 Not Found – This indicates that a resource is not found.
500 Internal server error – This is a generic server error. It probably shouldn’t be thrown explicitly.
502 Bad Gateway – This indicates an invalid response from an upstream server.
503 Service Unavailable – This indicates that something unexpected happened on server side (It can be anything like server overload, some parts of the system failed, etc.).
4 - Allow filtering, sorting, and pagination
5 - Maintain good security practices
For example, a normal user shouldn’t be able to access information of another user
6 - Cache data to improve performance
7 - Versioning our APIs
Comments
Post a Comment