tiny-fetch-json
v2.0.1
Published
Tiny wrapper around Fetch to query JSON APIs more easily
Readme
tiny-fetch-json
Tiny wrapper around Fetch to query JSON APIs more easily.
Requirements
- Node.js 18+ (or any environment with
fetchavailable)
Install
npm install tiny-fetch-jsonUsage
const fetchJson = require("tiny-fetch-json");
const res = await fetchJson("https://any.json.api", {
headers: { Authorization: "Bearer TOKEN" },
});
// `res` will be an object resulting from parsing the JSON responseAPI
fetchJson(resource, options)
Fetches JSON data from a URL.
- Throws an error if the request fails or the response is not 2xx.
- Returns a
Promisewith the response parsed as JSON.
resource
Type: string | URL | Request
The resource to fetch, i.e. the URL.
options
Type: RequestInit
Additional settings to apply to the request.
