Purescript-fetch (http-client)

@i-am-the-slime and I are happy to announce purescript-fetch.
purescript-fetch wraps the modern Fetch API for http requests and works on both web and node (>17.5). It is designed to be type-safe & easy to use and works well with purescript-yoga-json and purescript-argonaut.

11 Likes

Would you be willing to explain how this compares to Affjax? I know that with purs 0.15, Affjax now requires different packages depending on if you’re running in a browser or on node. Is that the main motivation for purescript-fetch?

1 Like

So purescript-affjax wraps the old XMLHttpRequest (aka AJAX) while purescript-fetch wraps the modern Fetch API. fetch has a couple of advantages over XMLHttpRequest like stream support, not sending cookies by default, etc, you can find more info on the web. affjax on node requires you to install an external dependency (xhr2) because it doesn’t support XMLHttpRequest. While the same was true for fetch in the past, this is not the case anymore. Starting with version 17.5 Node.js supports fetch. purescript-fetch reflects this, so you don’t need a node or web driver.
Some further improvements in comparison to previous libraries are better type safety, simpler usage and easy integration with yoga-json and argonaut.
Under the hood it is using a fork of web-fetch from purescript-web, our plan is to move this fork to purescript-contrib and deprecate web-fetch .

8 Likes