Skip to content

ehgoodenough/fetchquest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FetchQuest

An easier-to-use wrapper around window.fetch, so you don't have to write all that tedious syntax whenever you want to make a request.

Built on cross-fetch, so it works on both client and server.

How to Use

  • Accepts a request object, like you would with window.fetch.
  • Returns a promise with your response.
  • Throws an error if the response is a 4xx or 5xx.
  • If you response can be parsed a json, it is returned as json.
  • If your request body can be stringified, it is stringified.
FetchQuest({
    "method": "GET",
    "url": "https://github.com",
}).then((response) => {
    console.log(response)
})
FetchQuest({
    "method": "GET",
    "url": "https://github.com",
    "headers": {"Authorization": "Bearer 1234567890"}
}).then((response) => {
    console.log(response)
})
FetchQuest({
    "method": "POST",
    "url": "https://github.com",
    "body": {"message": "Hello World!"}
}).then((response) => {
    console.log(response)
})

About

A request wrapper around `window.fetch`

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published