Provides a wrapper around the browsers fetch API.

import { apprtFetch, ContentType} from "apprt-fetch";

// execute a get request
const response = await apprtFetch("https://httpbin.org/json", {
// query parameters f=json
query: { f: "json" },
headers: {
// accept only json responses
"Accept": ContentType.JSON
},
// throw error if response status is not 2XX
checkStatus: true
});

// Parse the response body as json.
const data = await response.json();
import { apprtFetchJson } from "apprt-fetch";

// execute a get request
const data = await apprtFetchJson("https://httpbin.org/json", {
// query parameters f=json
query: { f: "json" }
});
import { apprtFetch, ContentType } from "apprt-fetch";

// execute a POST request
const response = await apprtFetch("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: new URLSearchParams({ f: "json" })
});

// Parse the response body as json.
const data = await response.json();
import { apprtFetch, ContentType } from "apprt-fetch";

// execute a POST request
const response = await apprtFetch("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.
const data = await response.json();
import { apprtFetch, ContentType } from "apprt-fetch";

// execute a POST request
const response = await apprtFetch("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.
const data = await response.json();

Enumerations

ContentType

Interfaces

AfterInterceptorData
ApprtRequestInit
BeforeInterceptorData
Config
CustomFetch
Handle
Interceptor
ProxyRule
ProxyUrlOptions
TrustedServer

Type Aliases

ApprtRequestTarget
BasicFetchFunction
InterceptorOptions
ProxyMode

Functions

apprtFetch
apprtFetchJson
createCustomFetch
getConfig
getGlobalImpl
getProxiedUrl