2

I am trying to learn web services in general and have a small doubt.

When HTTP request is sent, if I mention a particular format (for example JSON) in Accept header and suppose server does not support that format, then will it be a network call error or server will still respond with whatever format it supports?

I know while sending a POST request, client sends another header by name "Content Type" and if that format is not supported by server, then it responds back with 415 error. (unsupported media type).

2 Answers 2

5

It's up to the server. It does not need to pay attention to the Accept header field.

A request without any Accept header field implies that the user agent will accept any media type in response. If the header field is present in a request and none of the available representations for the response have a media type that is listed as acceptable, the origin server can either honor the header field by sending a 406 (Not Acceptable) response or disregard the header field by treating the response as if it is not subject to content negotiation.

(from https://www.greenbytes.de/tech/webdav/rfc7231.html#rfc.section.5.3.2.p.7)

Sign up to request clarification or add additional context in comments.

Comments

0

For web services, the server will be responsible to denote the type of format that it intends to support, whether it is using JSON or XML.

Based on the data received from the client, the server should validate the format provided by the client. If it fits the specified format, then the server will respond accordingly to the intend of the end point. On the other hand, if it doesn't fit, the server should respond gracefully, indicating that the format (JSON/XML) is not supported by the web services.

I hope that answers your question. Have a nice day!

4 Comments

It still does not answer my question. The second case I have tested when I send a post request with content type not supported by server, then it returns an error (415) but i want to understand the behavior when I specify something specific in Accept header field (in request)
Sorry for misinterpreting your question. But it will be a 415 error if you specify something specific in Accept header field. The payload sent by the client should match whatever the server is expecting.
can you provide me some documentation link where it is mentioned? Because till now my finding has been slightly different in this case.
developer.mozilla.org/en-US/docs/Web/HTTP/Status/415 You may refer to this. It is quite comprehensive.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.