Ray
Ray

Reputation: 41428

For REST services that consume multiple formats, is there a generally accepted default Content Type?

If you have a REST service that accepts multiple formats:

Is there a widely accepted 'default' Content Type or:

For example, according to W3C the default content type for POST via HTML, is application/x-www-form-urlencoded.

Upvotes: 1

Views: 713

Answers (2)

Kylar
Kylar

Reputation: 9334

I strongly suggest that a server should reject a request that has a missing or inappropriate Content-Type header. RFC 7231 Has an explicit code for such:

6.5.13. 415 Unsupported Media Type

The 415 (Unsupported Media Type) status code indicates that the
origin server is refusing to service the request because the payload
is in a format not supported by this method on the target resource.
The format problem might be due to the request's indicated
Content-Type or Content-Encoding, or as a result of inspecting the
data directly.

Even though it doesn't explicitly mention a missing Content-Type, this is the accepted practice. See: HTTP status code for unaccepted Content-Type in request

Upvotes: 1

ChatterOne
ChatterOne

Reputation: 3541

Just as you should send the content-type in a response, you should also expect to have a content-type in the request.

Also, it's quite common to expect the correct content-type, see Jira REST API for instance:

Make sure the content type in the request is set to 'application/json', as shown in the example.

Or Twilio, where they have a list of accepted content-type and say:

If the content-type header does not match the media, Twilio will reject the request.

And I'm pretty sure that also the Outlook Mail REST API needs it to be correctly set.

So, yes, I'd say:"Don't accept a missing content type".

Upvotes: 1

Related Questions