package http_async
Async library for HTTP/1.1 servers
Install
Dune Dependency
Authors
Maintainers
Sources
http_async-0.1.1.tbz
sha256=3ec5bfa22b4ea06012af6920a9bd13c800ad5428a38281e48838e62b4ed0de64
sha512=e5ddfbb5ce2bab67fc2e754113dcc27a84be784c6b0fdb7682b56b6c86c3e86a80361b89a14b7033e879ea2e931be99255c9262192942642fdfd62f96a1e0ed7
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.
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 (_request, _body) ->
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 (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)
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page