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 result 
=> MisoString

url

-> [(MisoString, MisoString)]

headers

-> (result -> action)

successful callback

-> (MisoString -> 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 FetchGitHub =
  getJSON "https://api.github.com" [] SetGitHub ErrorHandler
updateModel (SetGitHub apiInfo) =
  info ?= apiInfo
updateModel (ErrorHandler msg) =
 io_ (consoleError msg)

postJSON Source #

Arguments

:: ToJSON body 
=> MisoString

url

-> body

Body

-> [(MisoString, MisoString)]

headers

-> action

successful callback

-> (MisoString -> action)

errorful callback

-> Effect parent model action 

putJSON Source #

Arguments

:: ToJSON body 
=> MisoString

url

-> body

Body

-> [(MisoString, MisoString)]

headers

-> action

successful callback

-> (MisoString -> action)

errorful callback

-> Effect parent model action 

Text

getText Source #

Arguments

:: MisoString

url

-> [(MisoString, MisoString)]

headers

-> (MisoString -> action)

successful callback

-> (MisoString -> action)

errorful callback

-> Effect parent model action 

postText Source #

Arguments

:: MisoString

url

-> MisoString

Body

-> [(MisoString, MisoString)]

headers

-> action

successful callback

-> (MisoString -> action)

errorful callback

-> Effect parent model action 

putText Source #

Arguments

:: MisoString

url

-> MisoString

Body

-> [(MisoString, MisoString)]

headers

-> action

successful callback

-> (MisoString -> action)

errorful callback

-> Effect parent model action 

Blob

getBlob Source #

Arguments

:: MisoString

url

-> [(MisoString, MisoString)]

headers

-> (Blob -> action)

successful callback

-> (MisoString -> action)

errorful callback

-> Effect parent model action 

postBlob Source #

Arguments

:: MisoString

url

-> Blob

Body

-> [(MisoString, MisoString)]

headers

-> action

successful callback

-> (MisoString -> action)

errorful callback

-> Effect parent model action 

putBlob Source #

Arguments

:: MisoString

url

-> Blob

Body

-> [(MisoString, MisoString)]

headers

-> action

successful callback

-> (MisoString -> action)

errorful callback

-> Effect parent model action 

Image

postImage Source #

Arguments

:: MisoString

url

-> Image

Body

-> [(MisoString, MisoString)]

headers

-> action

successful callback

-> (MisoString -> action)

errorful callback

-> Effect parent model action 

putImage Source #

Arguments

:: MisoString

url

-> Image

Body

-> [(MisoString, MisoString)]

headers

-> action

successful callback

-> (MisoString -> action)

errorful callback

-> Effect parent model action 

ArrayBuffer

getArrayBuffer Source #

Arguments

:: MisoString

url

-> [(MisoString, MisoString)]

headers

-> (ArrayBuffer -> action)

successful callback

-> (MisoString -> action)

errorful callback

-> Effect parent model action 

postArrayBuffer Source #

Arguments

:: MisoString

url

-> ArrayBuffer

Body

-> [(MisoString, MisoString)]

headers

-> action

successful callback

-> (MisoString -> action)

errorful callback

-> Effect parent model action 

putArrayBuffer Source #

Arguments

:: MisoString

url

-> ArrayBuffer

Body

-> [(MisoString, MisoString)]

headers

-> action

successful callback

-> (MisoString -> action)

errorful callback

-> Effect parent model action 

Header helpers

Types