Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags more
Archives
Today
Total
관리 메뉴

요리사에서 IT개발자로

스파르타 부트캠프 REST API 요청과 응답 (다락방) 본문

Spring

스파르타 부트캠프 REST API 요청과 응답 (다락방)

H.S-Backend 2024. 6. 14. 13:53

REST API란 

기능 명세만 보고도 어떤 방식으로 작동하는 지 알 수 있다.

위와 같이

API 명세서만 보고도 기능을 유추할 수 있어야 한다. 

 

유추한 바와 같이 작동을 한다면

REST Ful 하다고 할 수 있다.


POST 등록


GET 전체조회


선택조회


Students 테이블과  연관 관계인 Subjects 테이블이 있다면 

 

 위와같이 URL과 method만 보고도 기능을 유추할 수 있어야한다.

 

URL로 입력받는 방법에는

@PathVariable과 @RequestParam이 있다.

//URL로 입력받는 방법
//1. PathVariable(path)            -> /students/1
//2. RequestParam(parameter)       -> /students?number=20240614
/**
 * @PathVariable Long stduentId, @PathVariable Long subjectId
 *  -> /students/1/subjects/1
 */

/**
 * @RequestParam String studentNumber, @RequestParam String name
 * -> /students?number=20240614/name?=chris
 */

/**
 *  @GetMapping("/{studentId}/subjects/{subjectId}")
 *  public ResponseEntity<?> getStudentById(
 *  @PathVariable Long studentId,@PathVariable Long subjectId)
 */

/**
 * public ResponseEntity<?> sample(
 * @RequestParam String studentNumber,
 * @RequestParam String name)
 */

 

 

반응형