Content negotiation

The main definition of content negotiation is that it's an HTTP mechanism that enables different versions of specific representations of a resource at the same URI. Using this approach, the requester is able to specify which version fits their requirements. Of course, with TypeScript, it couldn't be different and you can easily enable that possibility.

One common way to specify the response body format is passing the payload at the header of the HTTP request, like so:

Accept: application/javascript

The following screenshot shows an example from Postman with the accept header as application/javascript:

Accept header definition ...

Get Hands-On RESTful Web Services with TypeScript 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.