REST Content-Type: Should it be based on extension or Accept header?

后端 未结 7 1366
旧时难觅i
旧时难觅i 2020-11-28 22:50

Should the representation(html, xml, json) returned by a RESTful web service be determined by the url or by the Accept HTTP header?

7条回答
  •  鱼传尺愫
    2020-11-28 23:32

    See Chapter 5 - Representational State Transfer (REST), section 5.2.1.2 Representations of Roy Fielding's dissertation on Architectural Styles:

    The data format of a representation is known as a media type [48].

    Looking at the link, we see that it refers to MIME. So I assume that in HTTP parlance, it is represented with a Content-Type header for POST/PUT and Accept header for GET.

    Here is the rest of the paragraph (for completeness):

    A representation can be included in a message and processed by the recipient according to the control data of the message and the nature of the media type. Some media types are intended for automated processing, some are intended to be rendered for viewing by a user, and a few are capable of both. Composite media types can be used to enclose multiple representations in a single message.

    P.S.: I am not sure why people never look in the place where REST is actually defined...

提交回复
热议问题