Data-Driven Fetch API
A small wrapper for fetch with data-driven approach
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" })
})
const request = dretch('https://jsonplaceholder.typicode.com')
const req = ['POST', '/todos', {
body: {
title: "Remember the milk"
}
}] as RequestData
const response = await request(...req)