A simple utility to make using fetch "easier" using a class based approach
- Easy to use
- Class-Based
- Light-Weight its just a simple wrapper around fetch
- Supports all normal fetch apis + adding queries
- Great typescript support types are automatically generated
import { doomFetch } from 'https://deno.land/x/doomfetch/mod.ts';Get the response and return the json
import { DenoModuleInterface } from 'somewhere.ts';
await doomFetch<DenoModuleInterface>('https://api.deno.land/modules', 'GET')
.query('query', 'doomfetch')
.query('limit', '1')
//The json has the `DenoModuleInterface` type
.json();await doomFetch(
'https://denolib.github.io/high-res-deno-logo/deno_hr.png'
).send('blob');
//Res.body now has the blob type and is a blobawait doomFetch('https://example.com').body({
name: 'skyblockdev',
});await doomFetch('https://example.com')
.header('Content-Type', 'application/json')
.text();await doomFetch('https://example.com')
.headers({ 'Content-Type': 'application/json' })
.text();neat shortcut that allows uploading arraybuffers/blobs/string as blob in formdata
await doomFetch('https://example.com').file(
await Deno.readFile('file.text'),
'data'
);Ever had to deal with a api that just randomly fails?
//5 being the amount of times to retry
doomFetch('https://example.com').retry(5).send();const request = doomFetch('https://example.com');
const request2 = request.clone();doomFetch('https://example.com/cool').setUrlPath('/404');doomFetch('https://example.com/cool').setUrl('https://youtube.com');You can use the from method.
import { DoomFetch } from 'https://deno.land/x/doomfetch/mod.ts';
DoomFetch.from('https://example.com', {
method: 'get',
body: JSON.stringify({
some: 'body',
}),
});or you can set the request
const req = doomfetch('https://example.com', 'GET').header('some', 'header');
req.request = {
headers: {
newheaders: 'are here',
},
};Redirect is a default thing and you can access it from doomFetch same for every other option in fetch
doomFetch('https://example.com').redirect(false);