How to do versioning in REST API

We can versionize REST Api in any one of the following ways.

1. Use the version in the REST Service URI as below

/api/v1/users

2. Pass the service version as a query param to the actual service as below

/api/users?version=v1
/api/users?v=v1

3. Use the date as version and pass it to the REST Api

/api/users?version=date

4. Using the customized accept header as like below

 @GET
    @Produces("application/vnd.bala-v1+json")
    @Path("version")
    public Response getVersion1() {
       String test="This is one of simple api to test. The version is 1";
       return Response.ok().entity(test).build();
    }

    @GET
    @Produces("application/vnd.bala-v2+json")
    @Path("version")
    public Response getVersion2() {
        String test="this is one of simple api to test. The version is 2";
        return Response.ok().entity(test).build();
    }

Then call the service as like below and pass the version in the accept header

curl --cookie "cookie name: cookie value" -H "accept:application/vnd.bala-v2+json" -X GET http://localhost:8080/api/server/version

5. Custom request header
Use the custom request header and pass the version in the http headers as like below. Note that your service should consume the api-version from the header and do the needful

curl --cookie "" -H "api-version:2" -X GET http://localhost:8080/api/users

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s