|
1 | 1 | # Content Negotiation
|
2 | 2 |
|
3 |
| -Content negotiation validation in DotKernel happened through middleware, and it ensures that the incoming request |
4 |
| -and the outgoing response conform to the content types specified in the config file for all routes or for a specific |
5 |
| -route. |
| 3 | +**Content Negotiation** is performed by an application in order : |
| 4 | + |
| 5 | +- To match the requested representation as specified by the client via the Accept header with a representation the |
| 6 | + application can deliver. |
| 7 | +- To determine the `Content-Type` of incoming data and deserialize it so the application can utilize it. |
| 8 | + |
| 9 | +Essentially, content negotiation is the *client* telling the server what it is sending and what it wants in return, and |
| 10 | +the server determining if it can do what the client requests. |
| 11 | + |
| 12 | +Content negotiation validation in **DotKernel API** happened through middleware, and it ensures that the incoming |
| 13 | +request and the outgoing response conform to the content types specified in the config file for all routes or for a |
| 14 | +specific route. |
6 | 15 |
|
7 | 16 | It performs validation on the `Accept` and `Content-Type` headers of the request and response and returning appropriate
|
8 | 17 | errors responses when necessary.
|
@@ -51,7 +60,7 @@ GET /admin HTTP/1.1
|
51 | 60 | Accept: application/json
|
52 | 61 | ```
|
53 | 62 |
|
54 |
| -This request indicates the client wants `applicaiton/json` in return. Now the server, through the config file will try |
| 63 | +This request indicates the client wants `application/json` in return. Now the server, through the config file will try |
55 | 64 | to validate if that representation can be returned, basically if `application/json` is presented in the `Accept` key.
|
56 | 65 |
|
57 | 66 | If the representation cannot be returned, a status code `406 - Not Acceptable` will be returned.
|
@@ -94,7 +103,7 @@ to be `multipart/form-data`. The above request will fail as the client send `app
|
94 | 103 | In addition to the validation described above, a third one is happening and is the last one, the server will check if
|
95 | 104 | the request `Accept` header can really be returned by the response.
|
96 | 105 |
|
97 |
| -Through how the DotKernel is returning a response in handler , a content type is always set, but this cannot be the case |
98 |
| -in any custom response but in any way the server will check what `Content-Type` the response is returning and will try |
99 |
| -to validate that against the `Accept` header of the request. If the validation fails, a status code |
| 106 | +Through how the **DotKernel API** is returning a response in handler , a content type is always set, but this cannot be |
| 107 | +the case in any custom response but in any way the server will check what `Content-Type` the response is returning and |
| 108 | +will try to validate that against the `Accept` header of the request. If the validation fails, a status code |
100 | 109 | `406 - Not Acceptable` will be returned.
|
0 commit comments