package http_async
Async library for HTTP/1.1 servers
Install
Dune Dependency
Authors
Maintainers
Sources
http_async-0.0.4.tbz
sha256=aae21a65c6b194accc0bb5c5c6191b1fec2ac4d5311e0038901f3f994315a982
sha512=21fe682c97fdc4ac318e75b310d471af29d6a09f7523191cec435aed514a0b69375dcf5100ef10c4ee3d38c3d19a87fe01cd4cfc443a209717b9e0246d09a01c
Description
README
Http_async
HTTP 1.1 server for async applications.
Getting Started
This library isn't published to the opam repository yet so it requires pinning to the development version of dependencies.
opam pin add -n http_async.dev git+https://github.com/anuragsoni/http_async.git
opam install http_async
Hello World
open! Core
open! Async
open Http_async
let () =
Command_unix.run
(Server.run_command ~summary:"Hello world HTTP Server" (fun _request ->
Service.respond_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
Service.respond_string (sprintf "Hello, %s" name) )
; ("/", fun _params _rest -> Service.respond_string "Hello World")
]
;;
let service request =
let path = Service.resource request in
match Dispatch.dispatch routes path with
| Some response -> response
| None -> Service.respond_string ~status:`Not_found "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