rest - Should response Content-Type always be same as Accept? -


i have resource original version of entity format , later, improved version breaking changes.

the caller opts later versions using accept header.

pretend moment service returns json.

should response application/json or format in accept header? care if cheat?

for example, or bad:

  • client request: get /people/1; accept: application/vnd.personv2+json
  • server response: 200 { "name": "john" }; content-type: application/json

the server has presented v2 person format using json, has said "just" normal application json, opposed saying format requested.

no, accept marks sort of content endpoint can handle. can endpoint deal json? xml? img? html? etc... more formally:

the accept request-header field can used specify media types acceptable response. accept headers can used indicate request limited small set of desired types, in case of request in-line image.

the content-type response has in payload in order request initiator know how handle. , formally:

the content-type entity-header field indicates media type of entity-body sent recipient or, in case of head method, media type have been sent had request been get.

for example - have endpoint in web-server accepts json (for example - client's data {'name': 'some-name', 'age': '30'}) , returns image (for example - descriptive image people in age 30). in case accept application/json , response img/*

this applies case. accept 1 thing, content-type another. not have same if semantically are.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -