Skip to content

Tricked-dev/doomfetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DoomFetch

A simple utility to make using fetch "easier" using a class based approach

Tables of Contents

Features:

  • 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

Using doomFetch

import { doomFetch } from 'https://deno.land/x/doomfetch/mod.ts';

Simple Example

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();

Fetching a image and getting the blob

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 blob

Sending a json body

await doomFetch('https://example.com').body({
	name: 'skyblockdev',
});

Specifying headers

await doomFetch('https://example.com')
	.header('Content-Type', 'application/json')
	.text();
await doomFetch('https://example.com')
	.headers({ 'Content-Type': 'application/json' })
	.text();

Sending a file

neat shortcut that allows uploading arraybuffers/blobs/string as blob in formdata

await doomFetch('https://example.com').file(
	await Deno.readFile('file.text'),
	'data'
);

Retrying

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();

Clone a request

const request = doomFetch('https://example.com');
const request2 = request.clone();

Changing the url path

doomFetch('https://example.com/cool').setUrlPath('/404');

Changing the url

doomFetch('https://example.com/cool').setUrl('https://youtube.com');

Creating a doomfetch instance from a fetch request

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',
	},
};

Using default request methods

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);

Documentation

About

A quick and easy fetch utlity for deno and the web using classes.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors