Created
September 21, 2014 19:12
-
-
Save sgrove/d8ac0427909774345d7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
S . | |
B _build | |
PKG core | |
PKG core_kernel | |
Pkg async | |
PKG core_extended | |
PKG lwt lwt.unix | |
PKG cohttp | |
EXT nonrec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#use "topfind";; | |
(* Added by OPAM. *) | |
let () = | |
try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH") | |
with Not_found -> () | |
;; | |
#camlp4o | |
#thread | |
#require "core.top";; | |
#require "async";; | |
open Core.Std | |
open Async.Std |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Seans-MacBook-Pro-2:hello_http sgrove$ eval `opam config env` | |
Seans-MacBook-Pro-2:hello_http sgrove$ opam list | |
Installed packages for system: | |
alcotest 0.2.0 Alcotest is a lightweight and colourful test framework | |
async 111.25.00 Monadic concurrency library | |
async_extra 111.25.00 Monadic concurrency library | |
async_graphics 0.5.1 Async wrapper for the OCaml Graphics library | |
async_kernel 111.25.00 Monadic concurrency library | |
async_unix 111.25.00 Monadic concurrency library | |
base-bigarray base Bigarray library distributed with the OCaml compiler | |
base-bytes legacy Bytes compatibility library distributed with ocamlfind | |
base-threads base Threads library distributed with the OCaml compiler | |
base-unix base Unix library distributed with the OCaml compiler | |
bin_prot 111.03.00 A binary protocol generator | |
biniou 1.0.9 Binary data format designed for speed, safety, ease of use and backward compatibility as protocols evolve | |
camlp4 4.01.0 Camlp4 is a system for writing extensible parsers for programming languages | |
camlzip 1.05 Provides easy access to compressed files in ZIP, GZIP and JAR format | |
camomile 0.8.5 A comprehensive Unicode library | |
cmdliner 0.9.5 Declarative definition of command line interfaces for OCaml | |
cohttp 0.11.2 HTTP library for Lwt, Async and Mirage | |
comparelib 109.60.00 Part of Jane Street’s Core library | |
conduit 0.5.1 Network connection library for TCP and SSL | |
core 111.25.00 Industrial strength alternative to OCaml's standard library | |
core_bench 109.58.01 Benchmarking library | |
core_extended 111.25.00 Extra components that are not as closely vetted or as stable as Core | |
core_kernel 111.25.00 Industrial strength alternative to OCaml's standard library | |
cppo 0.9.4 Equivalent of the C preprocessor for OCaml programs | |
crunch 1.3.0 Convert a filesystem into a static OCaml module | |
cryptokit 1.9 Cryptographic primitives library. | |
cstruct 1.4.0 access C structures via a camlp4 extension | |
custom_printf 111.25.00 Extension for printf format strings | |
dolog 0.5 the dumb OCaml logger (lazy and optionally colorful) | |
easy-format 1.0.2 High-level and functional interface to the Format module of the OCaml standard library | |
enumerate 111.08.00 Quotation expanders for enumerating finite types. | |
ezjsonm 0.2.0 An easy interface on top of the Jsonm library | |
fieldslib 109.20.03 Syntax extension to define first class values representing record fields, to get and set record fields, iterate and fold over all fields of a record and | |
git 1.2.0 Low-level Git bindings in pure OCaml | |
herelib 109.35.02 Part of Jane Street’s Core library | |
jsonm 0.9.1 Non-blocking streaming JSON codec for OCaml | |
lambda-term 1.6 Terminal manipulation library for OCaml | |
lwt 2.4.5 A cooperative threads library for OCaml | |
menhir 20130912 LR(1) parser generator | |
mstruct 1.3.0 Mstruct is a thin mutable layer on top of cstruct | |
ocamlfind 1.5.2 A library manager for OCaml | |
ocamlgraph 1.8.5 A generic graph library for OCaml | |
ocp-build 1.99.6-beta Project manager for OCaml | |
ocp-indent 1.4.1 A simple tool to indent OCaml programs | |
ocplib-endian 0.7 Optimised functions to read and write int16/32/64 from strings and bigarrays, based on new primitives added in version 4.01. | |
optcomp 1.6 Optional compilation with cpp-like directives | |
ounit 2.0.0 Unit testing framework loosely based on HUnit. It is similar to JUnit, and other XUnit testing frameworks | |
pa_bench 109.55.02 Syntax extension for inline benchmarks | |
pa_ounit 109.53.02 Syntax extension for oUnit | |
pa_test 111.08.00 Quotation expander for assertions. | |
pipebang 110.01.00 Part of Jane Street’s Core library | |
re 1.2.2 RE is a regular expression library for OCaml | |
re2 111.08.00 OCaml bindings for RE2, Google's regular expression library | |
react 1.1.0 Declarative events and signals for OCaml | |
sexplib 111.25.00 Library for serializing OCaml values to and from S-expressions | |
sha 1.9 Binding to the SHA cryptographic functions | |
ssl 0.4.7 Bindings for OpenSSL | |
stringext 1.0.0 Extra string functions for OCaml | |
textutils 111.25.00 Text output utilities | |
type_conv 111.13.00 Library for building type-driven syntax extensions | |
typerep 111.17.00 typerep is a library for runtime types. | |
typerex 1.99.6-beta Set of tools and libraries for OCaml, developed by OCamlPro and INRIA | |
uri 1.7.2 RFC3986 URI/URL parsing library | |
utop 1.14 Universal toplevel for OCaml | |
uutf 0.9.3 Non-blocking streaming Unicode codec for OCaml | |
variantslib 109.15.03 Part of Jane Street’s Core library | |
yojson 1.1.8 Yojson is an optimized parsing and printing library for the JSON format | |
zed 1.3 Abstract engine for text edition in OCaml | |
Seans-MacBook-Pro-2:hello_http sgrove$ ocaml server.ml | |
File "server.ml", line 2, characters 0-13: | |
Error: Unbound module Core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* This file is in the public domain *) | |
open Core.Std;; | |
open Async.Std;; | |
open Cohttp_async;; | |
(* given filename: hello_world.ml compile with: | |
$ corebuild hello_world.native -pkg cohttp.async | |
*) | |
let handler ~body:_ _sock req = | |
let uri = Cohttp.Request.uri req in | |
match Uri.path uri with | |
| "/test" -> | |
Uri.get_query_param uri "hello" | |
|> Option.map ~f:(fun v -> "hello: " ^ v) | |
|> Option.value ~default:"No param hello supplied" | |
|> Server.respond_with_string | |
| _ -> | |
Server.respond_with_string ~code:`Not_found "Route not found" | |
let start_server port () = | |
eprintf "Listening for HTTP on port %d\n" port; | |
eprintf "Try 'curl http://localhost:%d/test?hello=xyz'\n%!" port; | |
Cohttp_async.Server.create ~on_handler_error:`Raise | |
(Tcp.on_port port) handler | |
>>= fun _ -> Deferred.never () | |
let () = | |
Command.async_basic | |
~summary:"Start a hello world Async server" | |
Command.Spec.(empty +> | |
flag "-p" (optional_with_default 8080 int) | |
~doc:"int Source port to listen on" | |
) start_server | |
|> Command.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment