Skip to content

zaiste/dretch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dretch

Data-Driven Fetch API

A small wrapper for fetch with data-driven approach

Why?

Easier, data-driven syntax

This:

const request = dretch('https://jsonplaceholder.typicode.com')

const response = await request("POST", "/todos", {
  body: { title: "Remember the milk" }
})

instead of this:

const response = await fetch("https://jsonplaceholder.typicode.com/todos", {
  method: "POST",
  headers: { 
    "Content-Type": "application/json" 
  },
  body: JSON.stringify({ title: "Remember the milk" })
})

Use JavaScript data structures to describe requests

const request = dretch('https://jsonplaceholder.typicode.com')

const req = ['POST', '/todos', { 
  body: {
    title: "Remember the milk"
  }
}] as RequestData

const response = await request(...req)

About

Data-Driven wrapper for fetch

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors