You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by Pawel Kublas <pk...@gmail.com> on 2016/03/24 17:29:20 UTC

API versioning using Accept header

Hello,

I'm building REST API with Olingo V4 in Java.

I'm trying to figure out how to version the API using the Accept header of
the GET request, however, there is absolutely no information on how to do
that.

The goal is to support "Accept" : "application/json; version=1.0" .

The error I'm getting when I send request with the header above is this:

{
>
>     "error": {
>
>         "code": null,
>
>         "message": "The content-type range 'application/json; version=1.0'
>> is not supported as value of the Accept header."
>
>     }
>
> }
>
>

Is there any way to support Accept header with version parameter?

Regards

Re: API versioning using Accept header

Posted by "Bolz, Michael" <mi...@sap.com>.
Hi Pawel,

Yes, you can implement the “org.apache.olingo.server.api.serializer.CustomContentTypeSupport” interface
and register the according implementation at the “ODataHandler”.
There you can add your own accepted content types.
However, as Ramesh mentioned, the “version” added there does not belong to any OData version 
and has to be handled by your own service implementation (Olingo will only pass it through).

Below a short code snippet (sample with anonymous inner class):

> ODataHttpHandler handler = odata.createHandler(serviceMetadata);
> // Register helpers.
> handler.register(new CustomContentTypeSupport() {
>   @Override
>   public List<ContentType> modifySupportedContentTypes(List<ContentType> defaultContentTypes, RepresentationType type) {
>     List<ContentType> contentTypes = new ArrayList<ContentType>(defaultContentTypes);
>     contentTypes.add(ContentType.create("application/json; version=1.0"));
>     return contentTypes;
>   }
> });

Kind Regards,
Michael



> On 29 Mar 2016, at 00:08, Ramesh Reddy <ra...@redhat.com> wrote:
> 
> Please see this [1] for versioning in odata.
> 
> [1] http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part1-protocol/odata-v4.0-errata02-os-part1-protocol-complete.html#_Toc406398207 <http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part1-protocol/odata-v4.0-errata02-os-part1-protocol-complete.html#_Toc406398207>
> 
> Ramesh..
> http://teiid.org
> 
> Hello,
> 
> I'm building REST API with Olingo V4 in Java.
> 
> I'm trying to figure out how to version the API using the Accept header of the GET request, however, there is absolutely no information on how to do that.
> 
> The goal is to support "Accept" : "application/json; version=1.0" .
> 
> The error I'm getting when I send request with the header above is this: 
> 
> {
>     "error": {
>         "code": null,
>         "message": "The content-type range 'application/json; version=1.0' is not supported as value of the Accept header."
>     }
> }
> 
> 
> Is there any way to support Accept header with version parameter?
> 
> Regards
> 


Re: API versioning using Accept header

Posted by Ramesh Reddy <ra...@redhat.com>.
Please see this [1] for versioning in odata. 

[1] http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part1-protocol/odata-v4.0-errata02-os-part1-protocol-complete.html#_Toc406398207 

Ramesh.. 
http://teiid.org 

----- Original Message -----

> Hello,

> I'm building REST API with Olingo V4 in Java.

> I'm trying to figure out how to version the API using the Accept header of
> the GET request, however, there is absolutely no information on how to do
> that.

> The goal is to support "Accept" : "application/json; version=1.0" .

> The error I'm getting when I send request with the header above is this:

> > > {
> > 
> 
> > > "error": {
> > 
> 
> > > "code": null,
> > 
> 
> > > "message": "The content-type range 'application/json; version=1.0' is not
> > > supported as value of the Accept header."
> > 
> 
> > > }
> > 
> 
> > > }
> > 
> 
> Is there any way to support Accept header with version parameter?

> Regards