Java/Spring

Rest API Versioning

체리필터 2021. 6. 16. 09:28
728x90
반응형

https://www.springboottutorial.com/spring-boot-versioning-for-rest-services 참조

URL Path 방식, Param 방식, Header 방식, Media type versioning 등이 있음.

개인적으로 Header 방식 선호. 다음과 같은 방식으로 처리

  @GetMapping(value = "/student/header", headers = "X-API-VERSION=1")
  public StudentV1 headerV1() {
    return new StudentV1("Bob Charlie");
  }

  @GetMapping(value = "/student/header", headers = "X-API-VERSION=2")
  public StudentV2 headerV2() {
    return new StudentV2(new Name("Bob", "Charlie"));
  }

 

728x90
반응형