api-console icon indicating copy to clipboard operation
api-console copied to clipboard

Accept header does not reflect to raml mediaType

Open mmatloka opened this issue 10 years ago • 6 comments
trafficstars

We have an API versioning based on content types. My raml has defined a custom media type mediaType: application/vnd.sth-v1+json but the api-console performs requests with Accept: */*, instead of Accept: mediaType: application/vnd.sth-v1+json

mmatloka avatar Jun 19 '15 08:06 mmatloka

Hi @mmatloka, thanks for raising that. Can you please post an example of your RAML so that we can reproduce your issue.

sichvoge avatar Jun 19 '15 12:06 sichvoge

Hello, The minimum RAML:

#%RAML 0.8
title: Sth
version: 0.1
baseUri: http://localhost:8080/
mediaType: application/vnd.sth.storage-v1+json

/sth:
  get:

The request from the console looks like this (see the Accept: */*): HttpRequest(GET,http://localhost:8080/sth,List(Host: localhost:8080, Connection: keep-alive, Accept: */*, X-Requested-With: XMLHttpRequest, User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36, Referer: http://localhost:8080/console/index.html?raml=api/api.raml, Accept-Encoding: gzip, deflate, sdch, Accept-Language: pl-PL, pl;q=0.8, en-US;q=0.6, en;q=0.4, Cookie: scentry.auth.default.user=mmatloka; uvf=1; scentry.auth.default.user_530ded6fbab6d3ba00db0fdb=mmatloka; JSESSIONID=1mslcly8a2axr),Empty,HTTP/1.1)

Spec says: https://github.com/raml-org/raml-spec/blob/master/raml-0.8.md#default-media-type

The media types returned by API responses, and expected from API requests that accept a body, MAY be defaulted by specifying the mediaType property.

So I'd expect that the Console would perform requests using Accept: application/vnd.sth-v1+json instead.

mmatloka avatar Jun 19 '15 12:06 mmatloka

Thanks - we will take a look on that ;)

sichvoge avatar Jun 19 '15 12:06 sichvoge

At this point, API console does not set the Accept header in requests.

It would be a good feature to add, we would need to think of the following scenarios so that it works for all intended users:

  • Does console allow the user to pick one, when there are more than one, or does it just concatenate all?
  • if it does concatenate all, how does it order them in preference ?
  • API console should also allow users to override the value, so that devs can test how their APIs behave with different, wrong values in the headers.

dmartinezg avatar Jun 19 '15 13:06 dmartinezg

I vote Bummer because I, too, thought the API Console would use the default mediaType of the RAML spec. The current way it ignores that setting was not expected.

lonniev avatar Aug 24 '16 02:08 lonniev

the content-type in the request should be the mediaType from the raml file.

I testet it by adding a trait: traits:

  • contenttype_agnostic: headers: Content-Type: type: string

Otherwise I get an error: RESTEASY003065: Cannot consume content type

idefixcert avatar Oct 04 '16 06:10 idefixcert