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
- Automatically appends the version to the URI through the
@ApiVersion
annotation. - Allows customization of the URI prefix.
Maven:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Gradle:
repositories {
// ...
maven { url 'https://jitpack.io' }
}
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.
@EnableApiVersion
@SpringBootApplication
public class FooApplication {
public static void main(String[] args) {
SpringApplication.run(FooApplication.class, args);
}
}
@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");
}
}
GET http://localhost:8080/v1/foo
POST http://localhost:8080/v1.1/foo/bar
POST http://localhost:8080/v1.2/foo/bar
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
- Added
sharing-uri-prefix
property - Ability to create RequestMappingInfo with the previous path including prefix
- Fixed version mismatch error
- Fixed build error
- Initial release