Giter Site home page Giter Site logo

kjkrol / spring-boot-starter-web-http-versioninig-plugin Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 0.0 106 KB

API versioning plugin for Spring-Boot-Starter-Web using HTTP headers

Java 67.77% Groovy 32.23%
api-versioning versioning http java spring-boot-starter-web

spring-boot-starter-web-http-versioninig-plugin's Introduction

spring-boot-starter-web-http-versioninig-plugin

API versioning for org.springframework.boot:spring-boot-starter-web:5.x using HTTP header

This tiny spring-boot-starter-web plugin allows to versioning exposed REST API and accessing them using customized X-API-version HTTP headers.

Server side

Configuration: Two provided configuration classes:

  • ApiVersionConfiguration
  • ApiVersionResponseHeaderModifierAdvice

should be visible for spring ComponentScan. It can be done like that:

@SpringBootApplication(scanBasePackageClasses = {ApiVersionWebMvcRegistrations.class, ApiVersionResponseHeaderModifierAdvice.class})

To enable versioning for exposed Rest controller methods the following annotation should be used:

annotation description
@ApiVersion collects set of versions supported by annotted method
@ApiVersionLatest mark method as a latest (newest) version
@ApiVersionSupported mark method as supported by defult; allows to access method without using X-API-version header

Usage example:

@RestController
class ExampleController {

    @GetMapping(path = "/names", produces = APPLICATION_JSON_VALUE)
    @ApiVersion("1.0.0")
    List<String> getNames1() {
        return asList("Adam", "Noah");
    }

    @GetMapping(path = "/names", produces = APPLICATION_JSON_VALUE)
    @ApiVersion(["1.0.1", "1.0.2"])
    @ApiVersionSupported
    List<String> getNames2() {
        return asList("Abraham", "Joseph", "Moses");
    }

    @GetMapping(path = "/names", produces = APPLICATION_JSON_VALUE)
    @ApiVersion("1.0.3")
    @ApiVersionLatest
    List<String> getNames3() {
        return asList("Solomon", "David");
    }

}

Client side

  • To execute specific method version user should add X-API-version header to HTTP request
X-API-version: 1.0.2
  • Server will provide latest alias for the latest supported version
X-API-version: latest
  • If no X-API-version header is specified, server will execute default method (marked as @ApiVersionSupported)
  • Each HTTP response provides X-API-version header with information about executed method version
  • Specifying invalid (or unsupported) version will result in HTTP status 404 Not Found

spring-boot-starter-web-http-versioninig-plugin's People

Contributors

karoljkrol avatar kjkrol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.