@antoinette-agency/sofetch
v1.3.1
Published
An opinionated Fetch wrapper for JSON APIs
Downloads
86,811
Readme
✨ Features
- Elegant interface. Less code. Minimal boilerplate
- Serialise request ➡️ Post request ➡️ Serialise response with 1 line of code
- Fluent error handling
- Easy authentication
- Build multiple clients effortlessly
🌱 Install
npm i @antoinette-agency/sofetch⏩ Quickstart
import soFetch from "@antoinette-agency/sofetch";
//GET Request:
const products = await soFetch<Product[]>("/api/products")
//POST Request:
const newUser = {
name:"Regina George",
email:"[email protected]"
}
const successResponse = await soFetch<Success>("/api/users", newUser)
//Handling errors
const unicorn = await soFetch<Unicorn>("/api/unicorns/1234")
.catchHttp(HttpStatus.NotFound404, (res:Response) => {
alert("This unicorn can't be found")
})