버전 비교

  • 이 줄이 추가되었습니다.
  • 이 줄이 삭제되었습니다.
  • 서식이 변경되었습니다.

...

코드 블럭
languagejava
linenumberstrue
@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에서는 문장 내 공백을 하이픈으로 변경할 수 있음
밑줄(_)은 URI에 사용하지 않는다
  • 편집기 등에서 URI는 클릭이 가능한 Link 형태로 표시하여 _
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


코드 블럭
languagejava
linenumberstrue
@GetMapping("login")
public ModelAndView login(@RequestParam("index") int index, 
                                   @RequestParam("page") int page) {
  //...    
}


Path Variable/index/1@PathVariable


코드 블럭
languagejava
linenumberstrue
@PostMapping("index/{idx}")
@ResponseBody
public ModelAndView index(@PathVariable("idx") int index) {
  //...
}


...