package http_async
Async web toolkit
Install
Dune Dependency
Authors
Maintainers
Sources
http_async-0.0.2.tbz
sha256=4f82666745acd49bde3f7695d9543987d8fe40963c215d51a99c223d52b8198b
sha512=b3e67fa5407ac6e3a6d19e6abf1419d7ce2c060167a57914f17015fdf9180132baffe2293e21564d3467d469faeb0c85ee1b35ba90b805bba43e6264d6efd078
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 ->
let%bind () =
Pipe.iter_without_pushback
~f:(fun chunk -> Log.Global.info "%s" chunk)
(Service.body request)
in
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