Main difference to regular Response
and Request
types is that no manual JSON.stringify
and headers.set('Content-Type', ...)
is required.
In my opinion, JSONRequest
is the most lightweight way of fixing the biggest issue of the Fetch API when dealing with JSON APIs, without resorting to full alternatives such as superagent or axios.
Example:
const response = await fetch(new JSONRequest('/comments', {
method: 'POST',
body: { text: 'Usage example: ...' },