...
코드 블럭 | ||||
---|---|---|---|---|
| ||||
@GetMapping("/{id}") public ResponseEntity<?> getBazz(@PathVariable String id){ return new ResponseEntity<>(new Bazz(id, "Bazz"+id), HttpStatus.OK); } @PostMapping public ResponseEntity<?> newBazz(@RequestParam("name") String name){ return new ResponseEntity<>(new Bazz("5", name), HttpStatus.OK); } @PutMapping("/{id}") public ResponseEntity<?> updateBazz(@PathVariable String id, @RequestParam("name") String name) { return new ResponseEntity<>(new Bazz(id, name), HttpStatus.OK); } @DeleteMapping("/{id}") public ResponseEntity<?> deleteBazz(@PathVariable String id){ return new ResponseEntity<>(new Bazz(id), HttpStatus.OK); } |
URI 규칙
규칙 | 설명 |
---|---|
슬래시 구분자(/)는 계층 관계를 나타내는 데 사용한다 | http://api.canvas.restapi.org/shapes/polygons/quadrilaterals/squares
|
URI 마지막 문자로 슬래시(/)를 포함하지 않는다 | http://api.canvas.restapi.org/shapes http://api.canvas.restapi.org/shapes/ |
하이픈(-)은 URI 가독성을 높이는 데 사용한다 | http://api.example.restapi.org/blogs/mark-masse/entries/this-is-my-first-post
|
밑줄(_)은 URI에 사용하지 않는다 |
|
URI경로에는 소문자가 적합하다 | |
파일 확장자는 URI에 포함시키지 않는다 | |
API에 있어서 서브 도메인은 일관성 있게 사용해야 한다 | |
클라이언트 개발자 포탈 서브 도메인 이름은 일관성 있게 만들어야 한다 | |
http://hungry-developer.blogspot.com/2014/06/rest-api.html |
GET Method에서 파라미터 처리
파라미터 종류 | URL 형식 | Spring Annotation | 예시 | |||||||
---|---|---|---|---|---|---|---|---|---|---|
Request Parameter | /login?index=1&page=2 | @RequestParam |
| |||||||
Path Variable | /index/1 | @PathVariable |
|
...