json_ static method
The json()
static method of the Response interface returns a
Response
that contains the provided JSON data as body, and a header
which is set to application/json
.
The response status, status message, and additional headers can also be
set.
The method makes it easy to create Response
objects for returning JSON
encoded data.
Service workers,
for example, intercept fetch requests made by a browser, and might use
json()
to construct a Response
from cached JSON data to return to the
main thread.
The json()
method can also be used in server code to return JSON data
for
single page applications,
and any other applications where a JSON response is expected.
Implementation
@JS('json')
external static Response json_(
JSAny? data, [
ResponseInit init,
]);