Miso.Fetch module as a typed interface to the browser’s Fetch API. Functions are organized by the type of data being sent or received, and each integrates with miso’s Effect system via withSink.
JSON
The most common operations fetch or post JSON-encoded data.getJSON
Retrieves a JSON response from a URL.
Accept: application/json. On success the response body is decoded via FromJSON. On failure the error callback receives the raw response.
postJSON
Sends a POST request with a JSON-encoded body. Expects no response body.
postJSON'
Sends a POST request with a JSON-encoded body and expects a JSON response.
Content-Type: application/json and Accept: application/json.
putJSON
Sends a PUT request with a JSON-encoded body. Expects no response body.
Text
Blob
ArrayBuffer and Uint8Array
Image
FormData
Header helpers
Convenience constants for building header lists:=: utility from Miso.Util:
Miso.Fetch function sets automatically.
The Response type
Response is defined in Miso.FFI.Internal and carries both the decoded body and metadata:
Response, so status codes and error messages are always available even in the error branch.
Full example: fetching JSON in an update handler
This is the canonical pattern shown in thegetJSON Haddock documentation:
getJSON call is made directly in the update function. It returns an Effect that fires the sink with either SetGitHub or ErrorHandler once the HTTP response arrives.
Integration with withSink
All Miso.Fetch functions are built on top of withSink from Miso.Effect:
Effect values and can be used anywhere an Effect is expected.
Servant integration
For more complex APIs modelled with Servant, use servant-miso-client to derive typed client functions automatically. Add it to yourcabal.project: