# Headers & Content Negotiation — REST API Design

Source: https://www.geekswithgeeks.com/en/restapi/api-headers-negotiation

> How the client and server agree on the format of a message.

## Content-Type vs Accept

`Content-Type` tells the receiver what format the **body being sent** is in (`application/json`). `Accept` tells the server what format the **client wants back**. They can differ — a client might send form data but ask for a JSON response.

## A typical request

Headers carry metadata the URI and body shouldn't.

```http
POST /orders HTTP/1.1
Host: api.example.com
Content-Type: application/json
Accept: application/json
Authorization: Bearer eyJhbGciOi...

{ "productId": 42, "qty": 2 }
```

## Reject what you can't serve

If a client's `Accept` header asks for a format the server doesn't support, return `406 Not Acceptable` instead of silently sending something else.
