not really known
Go to file
2022-08-20 19:50:24 +01:00
.github/workflows Cleanup and polishing 2022-08-19 16:42:54 +01:00
src Remove unused import 2022-08-19 16:54:11 +01:00
test Cleanup and polishing 2022-08-19 16:42:54 +01:00
.gitignore Initial commit 2022-08-18 10:47:23 +01:00
packages.dhall Pin core v4.0.4 2022-08-20 19:50:24 +01:00
README.md Minor readme update 2022-08-19 18:35:13 +01:00
spago.dhall Cleanup and polishing 2022-08-19 16:42:54 +01:00
test.dhall Cleanup and polishing 2022-08-19 16:42:54 +01:00

purescript-fetch

High-level library for the WHATWG Fetch Living Standard.

purescript-fetch works on browser and Node.js. Running on Node.js requires version >17.5, see # Usage.

Installation

spago install fetch

Usage

Note: Node.js <17.5 is not supported. Node.js >=17.5 and <18.0 requires the --experimental-fetch node options:

NODE_OPTIONS=--experimental-fetch spago run

Node.js >18.0 you don't need to set the --experimental-fetch node option.

Perform a simple GET request:

fetch "https://httpbin.org/get" {} >>= _.text

Perform a POST request:

do
    { status, text } <- fetch "https://httpbin.org/post"
        { method: POST
        , mode: Cors
        , body: """{"hello":"world"}"""
        , headers: { "Content-Type": "application/json" }
        , referrer: (ReferrerUrl "https://httpbin.org")
        }
    responseText <- text

Json parsing

fetch works well with yoga-json and argonaut, use our little helper libraries.

yoga-json

You can use fetch-yoga-json helper library to simplify json handling

do
    { json } <- fetch "https://httpbin.org/post"
        { method: POST
        , body: writeJSON { hello: "world" }
        , headers: { "Content-Type": "application/json" }
        }
    { "data": d, url, origin } <- fromJSON json

argonaut

Coming soon!