zaiste / dretch

Data-Driven wrapper for fetch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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


Languages

Language:TypeScript 100.0%