Posts

Showing posts from August, 2021

creating and publishing npm package "fwap", a typescript fetch wrapper

Browser fetch is a simple well supported built in http api which we use for some apps at Opentable. But fetch has some differences to typical fetch libraries:  it does not throw for 4xx and 5xx responses, you have to check the ok property and if not true then it's a failed error code you have to call async json() on the response to convert to json (tiny tedium) So a simple wrapper facade over fetch to take care of these would be nice eh! And how about we use Typescript and use built in http types like RequestInit and Response as well as generics. That's what fwap is! and it's now available on npm. Of course our code has unit tests. Yes it's yet another fetch wrapper (yafwap was another name I considered) but it's also a good learning experience (it's the journey as much as the destination maaannnn) All my references are at the bottom of this post and I'm much indebted to those authors How I created: git init and npm init confirm fwap not already used add typ