Skip to content

GIVEN53/api-versioning-library

Repository files navigation

api-versioning-library

last-commit last-release release-version

The api-versioning Java library helps you manage the API version using Spring Boot projects. The library automatically adds the version to the URI and provides a way to manage the version of the controller.

Supports JDK 17, Spring Boot 3.x

Features

  • Automatically appends the version to the URI through the @ApiVersion annotation.
  • Allows customization of the URI prefix.

Getting Started

1. Add the JitPack repository to your build file

Maven:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Gradle:

repositories {
    // ...
    maven { url 'https://jitpack.io' }
}

2. Add the dependency

Maven:

<dependency>
    <groupId>com.github.GIVEN53</groupId>
    <artifactId>api-versioning-library</artifactId>
    <version>{version}</version>
</dependency>

Gradle:

dependencies {
        implementation 'com.github.GIVEN53:api-versioning-library:{version}'
}

Warning You need to replace {version} with the latest version.


Usage

1. @EnableApiVersion annotation on your Application class

@EnableApiVersion
@SpringBootApplication
public class FooApplication {
    public static void main(String[] args) {
        SpringApplication.run(FooApplication.class, args);
    }
}

2. @ApiVersion annotation on your Controller class or method

@ApiVersion("1")
@RestController
@RequestMapping("/foo")
public class FooController {

    @GetMapping
    public ResponseEntity<?> getFoo() {
        return ResponseEntity.ok("get v1");
    }

    @ApiVersion({"1.1", "1.2"})
    @PostMapping("/bar")
    public ResponseEntity<?> postBar() {
        return ResponseEntity.ok("post v1.1 or v1.2");
    }
}

3. Request

GET http://localhost:8080/v1/foo

POST http://localhost:8080/v1.1/foo/bar
POST http://localhost:8080/v1.2/foo/bar

Setting properties

api:
  version:
    uri-prefix: # The prefix of URI. Default is "". if you set /api, the URI will be "/api/v1/..."
    sharing-uri-prefix: # The uri-prefix property is shared with previous API specs that do not have the @ApiVersion annotation. Default is false.

logging:
  level:
    given:
      apiversion: # The log level of the library. Default is info

Changelog

0.2.0

  • Added sharing-uri-prefix property
  • Ability to create RequestMappingInfo with the previous path including prefix

0.1.2

  • Fixed version mismatch error

0.1.1

  • Fixed build error

0.1.0

  • Initial release

About

Version Management for REST API based on Spring MVC

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages