[WEEK 1] REVIEW
YC Tech Academy
REST API 설계 [참고]
Use JSON as the Format for Sending and Receiving Data
Use Nouns Instead of Verbs in Endpoints
- HTTP methods (GET, POST, PUT, PATCH, and DELETE) are already in verb form for performing basic CRUD (Create, Read, Update, Delete) operations.
EX) http://mysite.com/getPosts (X) -> https://mysite.com/posts (O)
- HTTP methods (GET, POST, PUT, PATCH, and DELETE) are already in verb form for performing basic CRUD (Create, Read, Update, Delete) operations.
Name Collections with Plural Nouns
EX) http://mysite.com/post/123 (X) -> https://mysite.com/posts/123 (O)
Use Status Codes in Error Handling
STATUS CODE RANGE MEANING 100 – 199 Informational Responses 300 – 399 Redirects 400 – 499 Client-side errors 500 – 599 Server-side errors
Use Nesting on Endpoints to Show Relationships
- You should avoid nesting that is more than 3 levels deep as this can make the API less elegant and readable.
EX) https://mysite.com/posts/postId/comments
- You should avoid nesting that is more than 3 levels deep as this can make the API less elegant and readable.
Use Filtering, Sorting, and Pagination to Retrieve the Data Requested
EX) https://mysite.com/posts?tags=javascript
Use SSL for Security
EX) https://mysite.com/posts runs on SSL. http://mysite.com/posts does not run on SSL.
Be Clear with Versioning
EX) https://mysite.com/v1/ for version 1 https://mysite.com/v2 for version 2
Provide Accurate API Documentation
- The documentation should contain:
- relevant endpoints of the API
- example requests of the endpoints
- implementation in several programming languages
- messages listed for different errors with their status codes
- The documentation should contain:
Controller 작성 & 설계
- Model과 View 사이를 이어주는 인터페이스 역할.
즉, Model이 데이터를 어떻게 처리할지 알려주는 역할을 수행. 사용자로부터 View에 요청이 있으면 Controller는 해당 업무를 수행하는 Model을 호출하고 Model이 업무를 모두 수행하면 다시 결과를 View에 전달하는 역할을 함.
- @Controller 와 @RestController의 차이
@Controller | @RestController |
---|---|
@Controller is used to mark classes as Spring MVC Controller. | @RestController annotation is a special controller used in RESTful Web services, and it’s the combination of @Controller and @ResponseBody annotation. |
It is a specialized version of @Component annotation. | It is a specialized version of @Controller annotation. |
In @Controller, we can return a view in Spring Web MVC. | In @RestController, we can not return a view. |
@Controller annotation indicates that the class is a “controller” like a web controller. | @RestController annotation indicates that class is a controller where @RequestMapping methods assume @ResponseBody |
In @Controller, we need to use @ResponseBody on every handler method. | In @RestController, we don’t need to use @ResponseBody on every handler method. |
728x90
반응형
'YC TECH ACADEMY' 카테고리의 다른 글
AWS 클라우드 컴퓨팅 (0) | 2023.11.27 |
---|---|
OAuth2.0 (0) | 2023.11.27 |
Spring Security (0) | 2023.11.27 |
[RDBMS] 테이블들의 연관 관계 & indexing & transaction & Spring Data JPA 활용 (0) | 2023.11.27 |
Bean 주입 & Bean Component 차이 & Field Injection, Constructor Injection 차이 & @Primary, @Qualifier annotation (0) | 2023.11.27 |