DELAPARRA
Index
Color
NL
Category: HTTP headers

Accept

Explained by Updated

What is Accept?

Accept: What response formats the client can handle. Server picks one in Content-Type. The Accept header tells the server which formats the client can handle. A browser asks for text/html, while an API client usually sends Accept: application/json. The server picks the best match and states its choice in the Content-Type of the response.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Accept

How is Accept used in practice?

The q values set preferences. text/html;q=0.9 means HTML is fine, but slightly less wanted than whatever has no q value. This is called content negotiation.

What should you keep in mind with Accept?

In practice, Accept explains some puzzling behaviour. A Laravel route that returns validation errors as a redirect in the browser returns JSON for the same request when the client sends Accept: application/json. If your API client receives an HTML error page instead of JSON, check this header first. Setting it correctly in every API call avoids a whole class of confusing bugs.

What does an example of Accept look like?

Accept: application/json, text/html;q=0.9

At a glance

CategoryHTTP headers
Explained by
Updated

More HTTP headers terms

All terms starting with A

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.