-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
155 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
open Fetch_native_lwt; | ||
module Fetch = Fetch_native_lwt; | ||
|
||
fetch("https://httpbin.org/get", ()) | ||
|> Lwt.map( | ||
fun | ||
| Ok({Response.body, status, url, _}) => { | ||
Printf.printf( | ||
"Status-Code: %d\nBody: %s\nUrl: %s", | ||
Response.Status.toCode(status), | ||
Response.Body.toString(body), | ||
url, | ||
); | ||
} | ||
| Error(_) => Printf.printf("That's an error"), | ||
) | ||
|> Lwt_main.run; | ||
Fetch.( | ||
fetch("https://httpbin.org/get", ()) | ||
|> Lwt.map( | ||
fun | ||
| Ok({Response.body, status, url, _}) => { | ||
Printf.printf( | ||
"Status-Code: %d\nBody: %s\nUrl: %s", | ||
Response.Status.toCode(status), | ||
Response.Body.toString(body), | ||
url, | ||
); | ||
} | ||
| Error(_) => Printf.printf("That's an error"), | ||
) | ||
|> Lwt_main.run | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "fetch-core", | ||
"version": "0.1.0", | ||
"description": "A fetch interface/functor for ReasonML/OCaml", | ||
"license": "MIT", | ||
"esy": { | ||
"build": "dune build --profile=release ./src/fetch-core", | ||
"buildDev": "refmterr dune build @all" | ||
}, | ||
"scripts": { | ||
"format": "esy dune build @fmt --auto-promote", | ||
"test": "esy dune runtest test" | ||
}, | ||
"dependencies": { | ||
"@opam/dune": "^1.11.1", | ||
"@opam/reason": "^3.5.0", | ||
"ocaml": "<4.8.0" | ||
}, | ||
"devDependencies": { | ||
"refmterr": "^3.2.2", | ||
"@opam/alcotest": "0.8.5", | ||
"@opam/js_of_ocaml-compiler": "3.4.0", | ||
"@opam/merlin": "^3.3.2", | ||
"@opam/rtop": "3.5.0", | ||
"@opam/utop": "2.4.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "fetch-native-lwt", | ||
"version": "0.1.0", | ||
"description": "Fetch client (Lwt) for native ReasonML/OCaml", | ||
"license": "MIT", | ||
"esy": { | ||
"build": "dune build --profile=release ./src/fetch-native-lwt", | ||
"buildDev": "refmterr dune build @all" | ||
}, | ||
"scripts": { | ||
"format": "esy dune build @fmt --auto-promote" | ||
}, | ||
"dependencies": { | ||
"@opam/dune": "^1.11.1", | ||
"@opam/reason": "^3.5.0", | ||
"@reason-native-web/morph_client": "^0.1.1", | ||
"ocaml": "<4.8.0" | ||
}, | ||
"devDependencies": { | ||
"refmterr": "^3.2.2", | ||
"@opam/merlin": "^3.3.2", | ||
"@opam/rtop": "3.5.0", | ||
"@opam/utop": "2.4.2" | ||
}, | ||
"resolutions": { | ||
"@opam/httpaf-lwt-unix": "anmonteiro/httpaf:httpaf-lwt-unix.opam#76b461bed081c64908fb1fdfa076ab2c936ca622", | ||
"@opam/httpaf-lwt": "anmonteiro/httpaf:httpaf-lwt.opam#76b461bed081c64908fb1fdfa076ab2c936ca622", | ||
"@opam/httpaf": "anmonteiro/httpaf:httpaf.opam#76b461bed081c64908fb1fdfa076ab2c936ca622" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Fetch | ||
|
||
A fetch interface/functor for ReasonML/OCaml. | ||
|
||
# Table of Contents | ||
|
||
- [What](#what) | ||
- [Why](#why) | ||
|
||
## What? | ||
|
||
Fetch aims to provide a common interface over different HTTP and Promise-implementations in the ReasonML/OCaml ecosystem. | ||
|
||
It is based on the Fetch-specification from [Whatwg](https://fetch.spec.whatwg.org/), but makes conscious trade-offs. It has also taken inspiration and attempted to follow community-idioms and best practices with regards to HTTP-requests. | ||
|
||
The goal is to be pluggable with any HTTP or Promise-implementation provided it conforms to the common interface. | ||
|
||
E.g. | ||
|
||
```re | ||
module Fetch = Fetch_core.Fetchify.Make({ | ||
module Response = { | ||
/* your implementation */ | ||
}; | ||
|
||
type t = Promise.t(result(Response.t, exn)); | ||
|
||
let make = (req: Request.t) => /* your custom implementation */ | ||
}); | ||
``` | ||
|
||
## Why? | ||
|
||
There are several different implementations for making HTTP-requests and for handling asynchronous code in the ReasonML/OCaml ecosystem. | ||
This is ultimately a good thing as helps in improving the ecosystem, and also, most times there isn't always a one-size fits all. | ||
|
||
The goal is to reduce the burden of transitioning between as well as picking a library to begin with. | ||
|
||
By making the implementation-details agnostic and trying to specify a common interface which is also a bit higher-level it hopefully strikes a good balance and can be useful for the community as a whole. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# fetch-native-lwt | ||
|
||
Fetch client for native ReasonML. | ||
|
||
## Getting started | ||
|
||
1. Install | ||
|
||
```sh | ||
esy add fetch-native-lwt | ||
``` | ||
|
||
2. Add Fetch to your dune libraries: | ||
|
||
```lisp | ||
(libraries ... fetch-native-lwt) | ||
``` | ||
|
||
3. Make your first request: | ||
|
||
```re | ||
open Fetch_native_lwt; | ||
|
||
fetch("https://httpbin.org/get", ()) | ||
|> Lwt.map( | ||
fun | ||
| Ok({Response.body, status, url, _}) => { | ||
Printf.printf( | ||
"Status-Code: %d\nBody: %s\nUrl: %s", | ||
Response.Status.toCode(status), | ||
Response.Body.toString(body), | ||
url, | ||
); | ||
} | ||
| Error(_) => Printf.printf("That's an error"), | ||
) | ||
|> Lwt_main.run; | ||
``` |
File renamed without changes.
File renamed without changes.