package http_async

Not available on OCaml 5.5
  1. Overview
  2. Docs
Async library for HTTP/1.1 servers

Install

dune-project
 Dependency

Authors

Maintainers

Sources

http_async-0.2.0.tbz
sha256=3ba4a210833e93a50ca2e539b38d29352f7c1b892fd7b7e89af4e788fafe905f
sha512=0bf256e969a49d45765f8b0e1a06d914c2bc45c4d6f4adc28ad4d2f68f52734b3de73e890a9b5501c8679fdca30191663372a5786e693d505b1640554068af94

Description

http_async implements an efficient HTTP/1.1 server. It uses the shuttle library for network IO, and provides an easy-to-use interface for writing async http services while minimal overhead on top of the user provided http handler.

Tags

http-server http http1.1 async

Added to opam-repository:

README

Http_async

HTTP 1.1 server for async applications.

Installation

To use the version published on opam:
opam install http_async
For the development version:
opam pin add http_async.dev git+https://github.com/anuragsoni/http_async.git

Hello World

open! Core
open! Async
open Http_async

let () =
  Command_unix.run
    (Server.run_command ~summary:"Hello world HTTP Server" (fun addr (request, _body) ->
       Log.Global.info
         "(%s): %s"
         (Socket.Address.Inet.to_string addr)
         (Request.path request);
       return (Response.create `Ok, Body.Writer.string "Hello World")))
;;

Routing?

Http_async doesn't ship with a router. There are multiple routing libraries available on opam and using Http_async with them should be fairly easy. As an example, integration with ocaml-dispatch can be done as so:

open! Core
open! Async
open Http_async

let routes =
  let open Dispatch in
  DSL.create
    [ ( "/hello/:name"
      , fun params _rest ->
          let name = List.Assoc.find_exn params ~equal:String.equal "name" in
          return (Response.create `Ok, Body.Writer.string (sprintf "Hello, %s" name)) )
    ; ("/", fun _params _rest -> Response.create `Ok, Body.Writer.string "Hello World")
    ]
;;

let service _addr (request, body) =
  let path = Request.path request in
  match Dispatch.dispatch routes path with
  | Some response -> response
  | None -> return (Response.create `Not_found, Body.Writer.string "Route not found")
;;

let () = Command_unix.run (Server.run_command ~summary:"Hello world HTTP Server" service)

Dependencies (4)

  1. ppxlib >= "0.23.0"
  2. shuttle >= "0.6.0" & < "0.9.0"
  3. ocaml >= "4.11.0"
  4. dune >= "2.9"

Dev Dependencies (1)

  1. odoc with-doc

Optional Dependencies

None

Used by

None

Conflicts

None

Build status

Results of building http_async with each compiler on check.ci.ocaml.org, run of against opam-repository 8a77e58. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
0.2.0 (this version) good good good n/a n/a
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure