• Stars
    star
    170
  • Rank 215,876 (Top 5 %)
  • Language
    OCaml
  • License
    BSD 3-Clause "New...
  • Created over 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Web library for OCaml with support for HTTP/1.X / HTTP/2

piaf

Piaf is a client library for the HTTP/1.X and HTTP/2 protocols written entirely in OCaml.

Installation

Piaf is released to OPAM.

You can depend on it via esy or by running opam install piaf.

Note: make sure to mirror Piaf's own resolutions located in the opam file.

Usage & Examples

TODO, read the mli file for now.

Examples

open Piaf

let get_sync env ~sw url =
  print_endline "Sending request...";
  match Client.Oneshot.get ~sw env (Uri.of_string url) with
  | Ok response ->
    if Status.is_successful response.status
    then Body.to_string response.body
    else
      let message = Status.to_string response.status in
      Error (`Msg message)
  | Error e -> failwith (Error.to_string e)

let () =
  Eio_main.run (fun env ->
      Eio.Switch.run (fun sw ->
          match get_sync env ~sw "https://example.com" with
          | Ok body -> print_endline body
          | Error error ->
            let message = Error.to_string error in
            prerr_endline ("Error: " ^ message)))

There's a more substantive example of using Piaf's API in bin/carl.ml, an implementation of a subset of curl, in caml.

Development

There's two ways to get a development environemnt up and running. If you have (or don't mind getting) nix installed, the repository includes scripts to set up a sandbox. Otherwise you can use opam to install the necessary dependencies globally.

Option 1) Setting up the sandbox

Assuming nix has been installed and set up, run nix develop -c $SHELL in the repository root. Once it's done building, you should have the development environment set up!

Option 2) Setting up opam

For this approach you'll need to install opam and set it up with a switch using ocaml >= 4.08. Once that's done, run opam pin . --deps-only to install the dependencies.

Note that this installs the dependencies globally, and that the development environment is dependent on the switch used.

Building

Run dune build to build, dune build --watch to run a watcher daemon that will build incrementally.

Running examples

Run dune exec examples/docs/readme.exe to run the simple example above.

Run dune exec bin/carl.exe to run carl, the curl-like example.

License & Copyright

Copyright (c) 2019 AntΓ³nio Nuno Monteiro

piaf is distributed under the 3-Clause BSD License, see LICENSE.

The vendor/multipart_form directory contains a fork of multipart_form which is licensed under the MIT License. multipart_form.LICENSE reproduces the original license text.

More Repositories

1

lumo

Fast, cross-platform, standalone ClojureScript environment
Clojure
1,888
star
2

ocaml-h2

An HTTP/2 implementation written in pure OCaml
OCaml
302
star
3

reason-graphql-fullstack

Fullstack Reason + GraphQL Todo List App
OCaml
248
star
4

aws-lambda-ocaml-runtime

An OCaml custom runtime for AWS Lambda
OCaml
201
star
5

archi

An OCaml library for managing the lifecycle of stateful components and their dependencies
OCaml
48
star
6

gluten

Reusable runtime library for network protocols
OCaml
44
star
7

om-next-fullstack

Fullstack application demoing Om Next server-side rendering.
Clojure
37
star
8

bucklescript-monorepo

Example of a BuckleScript monorepo setup
Reason
31
star
9

ocaml-quic

OCaml
30
star
10

github-stars-lambda-demo

OCaml
28
star
11

gh-feed-reader

OCaml
26
star
12

aemette

A batteries-included Leiningen template for Om
Clojure
24
star
13

dotfiles

Vim Script
23
star
14

now-static-bin

Run arbitrary executables in Now 2.0 Lambdas
Go
22
star
15

reason-graphql-experiment

Reason + GraphQL Fullstack (Native) experiment with Now 2.0
JavaScript
21
star
16

now-custom-runtime

ZEIT Now v2.0 builder for custom AWS Lambda runtimes
TypeScript
21
star
17

eio-ssl

OpenSSL bindings to OCaml EIO
OCaml
18
star
18

devcards-om-next

Devcards extension for writing fully reloadable Om Next cards
Clojure
16
star
19

ocaml-mongodb

OCaml
13
star
20

ocaml-subscriptions-transport-ws

Websocket protocol for exchanging GraphQL requests and responses
OCaml
12
star
21

snoopy-mode

Minor mode for number row unshifted character insertion in Emacs
Emacs Lisp
10
star
22

now-rust

Rust
10
star
23

youtube

Reason
9
star
24

graphql-sdl

OCaml
9
star
25

plomber

Component instrumentation for Om Next
Clojure
9
star
26

rekeys

Example ReasonML app to find JavaScript event keycodes.
OCaml
8
star
27

craftconf-demo

7
star
28

websocket-httpaf

OCaml
6
star
29

anmonteiro.github.io

πŸ’Ύ sources for my blog
Clojure
6
star
30

reason-lwt-tutorial

OCaml
6
star
31

ocaml-cpuinfo

OCaml
5
star
32

cra-reason-template

JavaScript
5
star
33

caqti-eio

OCaml
5
star
34

deathrow

πŸ”« Random last statements by executed offenders - web client
Clojure
4
star
35

M101JS

MongoDB University MongoDB for Node.js Developers course
JavaScript
4
star
36

melange-relay

Use Relay with ReScript.
OCaml
4
star
37

nixerve

OCaml
3
star
38

nowtop

OCaml
3
star
39

js-modules-demo

JS Modules demo with Om Next
Clojure
3
star
40

netlify-staging-example

JavaScript
3
star
41

stdlib-merge

OCaml
2
star
42

kubernetes-nixos

Nix
2
star
43

chital

πŸ‚ Scrape web pages for groups of articles
JavaScript
2
star
44

talks

Clojure
2
star
45

clj-isitup

πŸ’Ί isitup.org client, from your code or command line
Clojure
2
star
46

ocaml-sendfile

OCaml
1
star
47

AroundTheCorneriOS

Swift
1
star
48

diy-lisp

my implementation of diy-lisp (from kvalle/diy-lisp)
Python
1
star
49

lumo-demo

Clojure
1
star
50

next-netlify-starter-2

JavaScript
1
star
51

dune-repro

Nix
1
star
52

next-netlify-starter-demo

JavaScript
1
star
53

netlify-graph-nextjs-example

JavaScript
1
star
54

kpop-stack

TypeScript
1
star