Module
Fetch
- Package
- purescript-fetch
- Repository
- rowtype-yoga/purescript-fetch
#fetch Source
fetch :: forall input output thruIn thruOut headers. Union input thruIn (HighlevelRequestOptions headers String) => Union output thruOut UnsafeRequestOptions => ToCoreRequestOptions input output => String -> Record input -> Aff ResponseImplementation of fetch, see https://developer.mozilla.org/en-US/docs/Web/API/fetch
For usage with String bodies. For other body types, see fetchBody
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
#fetchBody Source
fetchBody :: forall input output thruIn thruOut headers body. ToRequestBody body => Union input thruIn (HighlevelRequestOptions headers body) => Union output thruOut UnsafeRequestOptions => ToCoreRequestOptions input output => String -> Record input -> Aff ResponseLike fetch, but can accept arbitrary RequestBodys.
Re-exports from Data.HTTP.Method
Re-exports from Fetch.Core.Integrity
Re-exports from Fetch.Core.Referrer
Re-exports from Fetch.Core.RequestCache
Re-exports from Fetch.Core.RequestCredentials
Re-exports from Fetch.Core.RequestMode
Re-exports from Fetch.Internal.Request
#HighlevelRequestOptions Source
type HighlevelRequestOptions :: Row Type -> Type -> Row Typetype HighlevelRequestOptions headers body = (body :: body, cache :: RequestCache, credentials :: RequestCredentials, 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
(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 -> Constraintclass 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 RequestBodyToCoreRequestOptionsConverter "credentials" RequestCredentials StringToCoreRequestOptionsConverter "cache" RequestCache StringToCoreRequestOptionsConverter "mode" RequestMode StringToCoreRequestOptionsConverter "referrer" Referrer StringToCoreRequestOptionsConverter "referrerPolicy" ReferrerPolicy StringToCoreRequestOptionsConverter "integrity" Integrity String
#ToCoreRequestOptionsHelper Source
class ToCoreRequestOptionsHelper :: forall k. Row Type -> k -> Row Type -> Constraintclass 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
#body Source
body :: Response -> Effect (ReadableStream Uint8Array)#arrayBuffer Source
arrayBuffer :: Response -> Aff ArrayBuffer