// execute a POST request constresponse = awaitapprtFetch("https://httpbin.org/post", { // declare that POST should be used method:"POST", // throw error if response status is not 2XX checkStatus:true, headers: { // accept only json responses "Accept":ContentType.JSON }, // Specify the POST-Body with URLSearchParams. // The "Content-Type" Header is automatically set to // "application/x-www-form-urlencoded;charset=UTF-8" body:newURLSearchParams({ f:"json" }) });
// Parse the response body as json. constdata = awaitresponse.json();
Example: POST x-www-form-urlencoded content with flag queryTransport:'form'
// execute a POST request constresponse = awaitapprtFetch("https://httpbin.org/post", { // declare that POST should be used method:"POST", // throw error if response status is not 2XX checkStatus:true,
headers: { // accept only json responses "Accept":ContentType.JSON },
// normally this would stay url parameters ?f=json query: { f:"json" },
// but this flags converts the query to the body queryTransport:"form" });
// Parse the response body as json. constdata = awaitresponse.json();
// execute a POST request constresponse = awaitapprtFetch("https://httpbin.org/post", { // declare that POST should be used method:"POST", // throw error if response status is not 2XX checkStatus:true, headers: { // Set the Content-Type of the body "Content-Type":ContentType.JSON_UTF8, // accept only json responses "Accept":ContentType.JSON }, // Specify the POST-Body body:JSON.stringify({ id:"test" }) });
// Parse the response body as json. constdata = awaitresponse.json();
Provides a wrapper around the browsers
fetch
API.Example: Fetch a json file
Example: Fetch a json file with apprtFetchJson
Example: POST x-www-form-urlencoded content
Example: POST x-www-form-urlencoded content with flag queryTransport:'form'
Example: POST application/json content