miso
Copyright(C) 2016-2025 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.Fetch

Description

Module for interacting with the Fetch API https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API manually.

Refer to the miso README if you want to automatically interact with a Servant API.

Synopsis

JSON

getJSON Source #

Arguments

:: (FromJSON body, FromJSVal error) 
=> MisoString

url

-> [(MisoString, MisoString)]

headers

-> (Response body -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

See https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API

data Action
 = FetchGitHub
 | SetGitHub GitHub
 | ErrorHandler MisoString
 deriving (Show, Eq)

updateModel :: Action -> Effect Model Action
updateModel = case
  FetchGitHub -> getJSON "https://api.github.com" [] SetGitHub ErrorHandler
  SetGitHub apiInfo -> info ?= apiInfo
  ErrorHandler msg -> io_ (consoleError msg)

postJSON Source #

Arguments

:: (FromJSVal error, ToJSON body) 
=> MisoString

url

-> body

Body

-> [(MisoString, MisoString)]

headers_

-> (Response () -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

putJSON Source #

Arguments

:: (FromJSVal error, ToJSON body) 
=> MisoString

url

-> body

Body

-> [(MisoString, MisoString)]

headers_

-> (Response () -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

Text

getText Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> [(MisoString, MisoString)]

headers_

-> (Response MisoString -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

postText Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> MisoString

Body

-> [(MisoString, MisoString)]

headers_

-> (Response () -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

putText Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> MisoString

Body

-> [(MisoString, MisoString)]

headers_

-> (Response () -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

Blob

getBlob Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> [(MisoString, MisoString)]

headers_

-> (Response Blob -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

postBlob Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> Blob

Body

-> [(MisoString, MisoString)]

headers_

-> (Response () -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

putBlob Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> Blob

Body

-> [(MisoString, MisoString)]

headers_

-> (Response () -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

FormData

getFormData Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> [(MisoString, MisoString)]

headers_

-> (Response FormData -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

postFormData Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> FormData

Body

-> [(MisoString, MisoString)]

headers_

-> (Response () -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

putFormData Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> FormData

Body

-> [(MisoString, MisoString)]

headers_

-> (Response () -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

Uint8Array

getUint8Array Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> [(MisoString, MisoString)]

headers_

-> (Response Uint8Array -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

postUint8Array Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> Uint8Array

Body

-> [(MisoString, MisoString)]

headers_

-> (Response () -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

putUint8Array Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> Uint8Array

Body

-> [(MisoString, MisoString)]

headers_

-> (Response () -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

Image

postImage Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> Image

Body

-> [(MisoString, MisoString)]

headers_

-> (Response () -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

putImage Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> Image

Body

-> [(MisoString, MisoString)]

headers_

-> (Response () -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

ArrayBuffer

getArrayBuffer Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> [(MisoString, MisoString)]

headers_

-> (Response ArrayBuffer -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

postArrayBuffer Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> ArrayBuffer

Body

-> [(MisoString, MisoString)]

headers_

-> (Response () -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

putArrayBuffer Source #

Arguments

:: FromJSVal error 
=> MisoString

url

-> ArrayBuffer

Body

-> [(MisoString, MisoString)]

headers_

-> (Response () -> action)

successful callback

-> (Response error -> action)

errorful callback

-> Effect parent model action 

Header helpers

Types

data Response body Source #

Instances

Instances details
Functor Response Source # 
Instance details

Defined in Miso.FFI.Internal

Methods

fmap :: (a -> b) -> Response a -> Response b #

(<$) :: a -> Response b -> Response a #

FromJSVal body => FromJSVal (Response body) Source # 
Instance details

Defined in Miso.FFI.Internal

Internal

fetch Source #

Arguments

:: (FromJSVal success, FromJSVal error) 
=> MisoString

url

-> MisoString

method

-> Maybe JSVal

body

-> [(MisoString, MisoString)]

headers

-> (Response success -> JSM ())

successful callback

-> (Response error -> JSM ())

errorful callback

-> CONTENT_TYPE

content type

-> JSM () 

Retrieve JSON via Fetch API

Basic GET of JSON using Fetch API, will be expanded upon.

See https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API