dretch
v0.3.0
Published
A small fetch wrapper with a data-driven API
Downloads
4
Readme
dretch
Data-Driven Fetch API
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)