Skip to content

Commit

Permalink
chore: mono-repo
Browse files Browse the repository at this point in the history
  • Loading branch information
lessp committed Sep 28, 2019
1 parent b73e8b1 commit b2273d0
Show file tree
Hide file tree
Showing 26 changed files with 155 additions and 19 deletions.
4 changes: 2 additions & 2 deletions esy.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "fetch",
"version": "0.1.0",
"description": "A fetch library for ReasonML/OCaml",
"description": "Fetch libraries and interface for ReasonML/OCaml",
"license": "MIT",
"esy": {
"build": "dune build -p fetch-core",
"build": ["dune build -p fetch-core", "dune build -p fetch-native-lwt"],
"buildDev": "refmterr dune build @all"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions esy.lock/index.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 17 additions & 15 deletions examples/fetch_native_lwt_get.re
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
);
27 changes: 27 additions & 0 deletions fetch-core.json
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"
}
}
30 changes: 30 additions & 0 deletions fetch-native-lwt.json
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"
}
}
39 changes: 39 additions & 0 deletions src/fetch-core/README.md
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.
38 changes: 38 additions & 0 deletions src/fetch-native-lwt/README.md
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.

0 comments on commit b2273d0

Please sign in to comment.