Copyright | (C) 2016-2025 David M. Johnson |
---|---|
License | BSD3-style (see the file LICENSE) |
Maintainer | David M. Johnson <code@dmj.io> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Miso.Fetch
Contents
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
- fetch :: FromJSON result => MisoString -> MisoString -> Maybe Body -> [(MisoString, MisoString)] -> (result -> action) -> (MisoString -> action) -> Effect parent model action
- accept :: MisoString
- contentType :: MisoString
- applicationJSON :: MisoString
- type Body = JSVal
Function
Arguments
:: FromJSON result | |
=> MisoString | url |
-> MisoString | method |
-> Maybe Body | body |
-> [(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 = let headers = [ accept =: applicationJSON ] fetch "https://api.github.com" GET Nothing headers SetGitHub ErrorHandler updateModel (SetGitHub apiInfo) = info ?= apiInfo updateModel (ErrorHandler msg) = io_ (consoleError msg)
Header helpers
accept :: MisoString Source #