package melange-fetch

  1. Overview
  2. Docs
Fetch API support for Melange

Install

Dune Dependency

Authors

Maintainers

Sources

melange-fetch-0.1.0.tbz
sha256=88fa27e183aa943496519f0ffaee7dbc98f102935285c71f17353ec9b344ff78
sha512=41f7ba39f0c7ce6a9dc399488a2b8aceab11ed5bd3aa2e9254a31ff607c9558e76f61d54b8081dc40400fa6ed86097b7d962a7b6f68fab1bcf025f54a1a4169d

Description

Published: 28 Sep 2023

README

melange-fetch

Low-level bindings to fetch for Melange.

melange-fetch is intended as a thin layer atop the JS API, upon which more high-level and idiomatic libraries can be made. Once such a library has been established, these bindings will likely be refactored to be even thinner.

Example

Js.Promise.(
  Fetch.fetch("/api/hellos/1")
  |> then_(Fetch.Response.text)
  |> then_(text => print_endline(text) |> resolve)
);

Installation

opam pin add melange-fetch.dev git+https://github.com/melange-community/melange-fetch.git#master

Then add melange-fetch to the libraries field in your dune file:

(melange.emit ;; or (library ...)
 ...
 (libraries melange-fetch))

Usage

See usage examples in ocaml_examples.ml and reason_examples.re. The source is a single file!

Node.js polyfill

fetch is a Web API that isn't available out-of-the-box in Node.js, and will therefore need to be polyfilled. isomorphic-fetch one such polyfill that seems to work well. Just install it via npm and add [%raw "require('isomorphic-fetch')"] to the top of your main file, but be aware that there are some subtle differences and even parts that are missing entirely.

Changes

0.6.2

  • Added FormData bindings

0.6.0

  • Bugfix: Response._type was generating _type instead of type

  • Breaking: Rename Response._type to Response.type_ to follow the name mangling convention trends

0.5.2

  • Added AbortController

0.5.0

  • Fixed Headers.append and Headers.delete. They were missing the return type.

0.4.0

  • Bumped bs-platform to 5.0.4 to stop compiler from complaining.

0.3.0

  • Added HeadersInit.makeWithDict so as to be able to make headers in OCaml too

  • Require bs-platform >= 3.0.0 due to internal dependency on Js.boolean that has now been removed

0.2.0

  • Rename Bs_fetch module to Fetch. Bs_fetch is kept around as an alias for backwards compatibility, but should be considered deprecated.

Dependencies (3)

  1. melange >= "2.0.0"
  2. ocaml
  3. dune >= "3.8"

Dev Dependencies (1)

  1. odoc with-doc

Used by (1)

  1. melange-webapi

Conflicts

None