mirror of
https://github.com/rowtype-yoga/purescript-fetch.git
synced 2024-11-26 07:41:31 +03:00
not really known
.github/workflows | ||
src | ||
test | ||
.gitignore | ||
packages.dhall | ||
README.md | ||
spago.dhall | ||
test.dhall |
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!