Hypermedia As The Engine of Application State
-> 다음 요청을 위한 하이퍼링크가 제공되어야 한다
{
"data": {
"id": 1000,
"name": "게시글 1",
"content": "HAL JSON을 이용한 예시 JSON",
"self": "http://localhost:8080/api/post/1000", // 호출한 api 주소
"profile": "http://localhost:8080/docs#query-article", // 호출한 api 문서
"next": "http://localhost:8080/api/post/1001", // 다음 post를 조회 api 주소
"comment": "http://localhost:8080/api/post/comment", // post의 댓글 달기 api 주소
"save": "http://localhost:8080/api/feed/post/1000", // post을 내 피드로 저장 api 주소
},
}
// SpringBoot HATEOAS 의존성 추가
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
예시
@RestController
public class ChannelController {
@Autowired
ChannelRepository channelRepository;
@GetMapping("/channels")
public PagedModel<User> getUsers(Pageable pageable, PagedResourcesAssembler<User> assembler) {
var all = channelRepository.findAll(pageable);
return assembler.toModel(all);
}
}
!! JPA 로 쿼리를 짜기 매우 어려운데 왜 다들 JPA만 쓰나요? !!