Stream: implementers
Topic: REST API and Accept header
Valery Kirichenko (Oct 27 2017 at 08:10):
Hi all! I am a little bit confused with implementation of REST API. According to RFC (https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1), Accept header can only include the media type and quality,
But reading the FHIR implementation guides of REST I noticed the following:
Requests MAY also specify this charset parameter in the Accept header and/or use the Accept-Charset header.
This phrase contradicts the RFC. Is'n it?
More over. Implementation of .NET API by Ewout Kramer (https://github.com/ewoutkramer/fhir-net-api) fills the accept header with value of the Content-Type header. Content-Type MAY include charset.
Vadim Peretokin (Oct 27 2017 at 08:20):
@Valery Kirichenko it's not forbidden to do that though, and I've seen other APIs use it
Valery Kirichenko (Oct 27 2017 at 08:37):
@Vadim Peretokin The problem with default implementation of Accept header parsing in the asp.net core mvc. According to its implemettation Accept header is parsed as "MediaTypeSegmentWithQuality" (https://github.com/aspnet/Mvc/blob/c27b07ef3f8b07dfe1d1de38a8d7bf2d6a9298f4/src/Microsoft.AspNetCore.Mvc.Core/Internal/AcceptHeaderParser.cs) wich can only include the Media type and Quality. Accept header with charset is invalid.
So we have to write a bad-smell code :blush: to provide acception of charset in Accept header =)
Grahame Grieve (Oct 27 2017 at 20:33):
I don't see where that rfc says that accept header can only include media type and qulity. Specifically, it discusses the use of a q parameter and points out that this means that media types can't define and use parameters named 'q' - that means that other parameters are ok. Suggest you file a bug against ASP...
Valery Kirichenko (Oct 30 2017 at 11:50):
On a further research I find out that according to IANA, some media types are support optional parameter charset
and the other ones not.
For example, application/json
does not support charset (https://www.iana.org/assignments/media-types/application/json), but application/xml
does (https://www.iana.org/assignments/media-types/application/xml). And all text/*
media type also support charset.
So we decided to follow the FHIR implementation guides. Thank you
Last updated: Apr 12 2022 at 19:14 UTC