Module

Fetch

Package
purescript-fetch
Repository
rowtype-yoga/purescript-fetch

#fetch Source

fetch :: forall input output @thruIn thruOut headers body. Union input thruIn (HighlevelRequestOptions headers body) => Union output thruOut UnsafeRequestOptions => ToCoreRequestOptions input output => String -> Record input -> Aff Response

Implementation of fetch, see https://developer.mozilla.org/en-US/docs/Web/API/fetch

Usage:

do
  let requestUrl = "https://httpbin.org/get"
  { status, text } <- fetch requestUrl { headers: { "Accept": "application/json" }}
  responseBody <- text

A more complex example doing a Post request:

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

Re-exports from Data.HTTP.Method

#Method Source

data Method

The definition of the type is based on HTTP/1.1 with RFC 2518 and RFC 5789.

Constructors

Instances

Re-exports from Fetch.Internal.Headers

Re-exports from Fetch.Internal.Request

#HighlevelRequestOptions Source

type HighlevelRequestOptions :: Row Type -> Type -> Row Typetype HighlevelRequestOptions headers body = (body :: body, cache :: RequestCache, credentials :: RequestCredentials, duplex :: Duplex, headers :: Record headers, integrity :: Integrity, method :: Method, mode :: RequestMode, referrer :: Referrer, referrerPolicy :: ReferrerPolicy)

#ToCoreRequestOptions Source

class ToCoreRequestOptions :: Row Type -> Row Type -> Constraintclass ToCoreRequestOptions input output | input -> output

Instances

#ToCoreRequestOptionsHelper Source

class ToCoreRequestOptionsHelper :: forall k. Row Type -> k -> Row Type -> Constraintclass ToCoreRequestOptionsHelper input inputRL output | inputRL -> output where

Members

Instances

#new Source

new :: forall input thru. Union input thru UnsafeRequestOptions => String -> Record input -> Effect Request

Re-exports from Fetch.Internal.RequestBody

Re-exports from Fetch.Internal.Response

#ResponseR Source

type ResponseR :: Row Typetype ResponseR = (arrayBuffer :: Aff ArrayBuffer, blob :: Aff Blob, body :: Effect (ReadableStream Uint8Array), headers :: Map CaseInsensitiveString String, json :: Aff Foreign, ok :: Boolean, redirected :: Boolean, status :: Int, statusText :: String, text :: Aff String, url :: String)

Re-exports from JS.Fetch.Integrity

Re-exports from JS.Fetch.Referrer

Re-exports from JS.Fetch.RequestCache

Re-exports from JS.Fetch.RequestCredentials

#RequestCredentials Source

Re-exports from JS.Fetch.RequestMode

#RequestMode Source