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
Re-exports from Fetch.Internal.Headers
Re-exports from Fetch.Internal.Request
#HighlevelRequestOptions Source
type HighlevelRequestOptions :: Row Type -> Type -> Row Type
type 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 -> Constraint
class ToCoreRequestOptions input output | input -> output
Instances
(Union rIn thru (HighlevelRequestOptions headers body), RowToList rIn rInRL, ToCoreRequestOptionsHelper rIn rInRL rOut) => ToCoreRequestOptions rIn rOut
#ToCoreRequestOptionsConverter Source
class ToCoreRequestOptionsConverter :: forall k. k -> Type -> Type -> Constraint
class ToCoreRequestOptionsConverter sym input output | sym input -> output where
Members
convertImpl :: Proxy sym -> input -> output
Instances
ToCoreRequestOptionsConverter "method" Method String
(Homogeneous r String) => ToCoreRequestOptionsConverter "headers" (Record r) Headers
(ToRequestBody body) => ToCoreRequestOptionsConverter "body" body RequestBody
ToCoreRequestOptionsConverter "credentials" RequestCredentials String
ToCoreRequestOptionsConverter "cache" RequestCache String
ToCoreRequestOptionsConverter "mode" RequestMode String
ToCoreRequestOptionsConverter "referrer" Referrer String
ToCoreRequestOptionsConverter "referrerPolicy" ReferrerPolicy String
ToCoreRequestOptionsConverter "integrity" Integrity String
ToCoreRequestOptionsConverter "duplex" Duplex String
#ToCoreRequestOptionsHelper Source
class ToCoreRequestOptionsHelper :: forall k. Row Type -> k -> Row Type -> Constraint
class ToCoreRequestOptionsHelper input inputRL output | inputRL -> output where
Members
convertHelper :: Proxy inputRL -> Record input -> Record output
Instances
ToCoreRequestOptionsHelper r Nil ()
(ToCoreRequestOptionsConverter sym tpeIn tpeOut, Cons sym tpeIn tailIn r, RowToList tailIn tailInRL, Lacks sym tailIn, IsSymbol sym, ToCoreRequestOptionsHelper tailIn tailInRL tailOutput, Cons sym tpeOut tailOutput output, Lacks sym tailOutput) => ToCoreRequestOptionsHelper r (Cons sym tpeIn tailInRL) output
Re-exports from Fetch.Internal.RequestBody
#ToRequestBody Source
Re-exports from Fetch.Internal.Response
#ResponseR Source
type ResponseR :: Row Type
type 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)
#body Source
body :: Response -> Effect (ReadableStream Uint8Array)
#arrayBuffer Source
arrayBuffer :: Response -> Aff ArrayBuffer