Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache header Content-Type vendor specific type/json

I am quite confused with the Content-Type vendor specific. Say by default,

Content-Type: application/json

but with vendor specific type, I can have this

Content-Type: application/vnd.anything.process-v1+json

Do I need to have any special function to do in PHP to use if I would check if the Content-Type is not vendor specific?

like image 684
planet x Avatar asked Sep 12 '26 08:09

planet x


1 Answers

If you are accepting content via HTTP POST from a client you can check the content type with $_SERVER['CONTENT_TYPE']. I would encourage you to use the @ver attribute in the Content-Type header instead of embedding in your vendor content type name. Example:

Content-Type: application/vnd.anything.process+json;ver=1

If you are sending content to a server via HTTP POST you need to specify an accept header to tell the client to return the data in the vendor specific content type. Something like this would work:

header('Accept: application/vnd.anything.process+json;ver=1');

Accept headers can be quite complicated though. If you do not control the server you are posting to as client, you should provide a sensible default to your Accept header. Something like this is more friendly if you want the server to send back plain JSON if it doesn't understand the vendor header:

header('Accept: application/vnd.anything.process+json;ver=1;q=0.9, application/json;q=0.1');

The most permissive Accept headers accept anything though:

header('Accept: application/vnd.anything.process+json;ver=1;q=0.9, application/json;q=0.5, */*;q=0.1');

Here is the actual RFC for Accept headers: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

like image 160
Herman J. Radtke III Avatar answered Sep 13 '26 23:09

Herman J. Radtke III



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!