MIME Types
An API can accept and return data in different formats, the most common being JSON and XML. You can use the consumes
and produces
keywords to specify the MIME types understood by your API. The value of consumes
and produces
is an array of MIME types. Global MIME types can be defined on the root level of an API specification and are inherited by all API operations. Here the API uses JSON and XML:
Note that consumes
only affects operations with a request body, such as POST, PUT and PATCH. It is ignored for bodiless operations like GET. When used on the operation level, consumes
and produces
override (not extend) the global definitions. In the following example, the GET /logo
operation redefines the produces
array to return an image:
MIME types listed in consumes
and produces
should be compliant with RFC 6838. For example, you can use standard MIME types such as:
as well as vendor-specific MIME types (indicated by vnd.
):
Did not find what you were looking for? Ask the community
Found a mistake? Let us know