Commit 397bbeb1 authored by Josh Kunz's avatar Josh Kunz

Adds the three basic endpoints.

parent c30ce8f4
......@@ -11,14 +11,18 @@ interfaces = $(patsubst %.mli,%.cmi,$(filter %.mli,$(sources)))
interfaces += $(patsubst %.ml,%.cmi,$(filter %.ml,$(sources)))
objects = $(patsubst %.ml,%.cmo,$(filter %.ml,$(sources)))
system_libs = unix threads
local_libs = json http
local_libs = jsonm http
depfile = Makefile.d
libloc = ../lib
abs_libs = $(addprefix $(libloc)/,$(addsuffix .cma,$(local_libs)))
default: $(bin)
$(abs_libs):
$(foreach lib,$(addsuffix .cma,$(local_libs)),$(MAKE) -C $(libloc) $(lib);)
$(depfile): $(sources)
abs_libs = $(addprefix ../lib/,$(addsuffix .cma,$(local_libs)))
$(bin): $(abs_libs) $(objects)
ocamlc $(OCAMLFLAGS) -o $@ $(addsuffix .cma,$(system_libs)) $^
......
......@@ -8,12 +8,29 @@ open HTTP
open Thread
open Mutex
(* Close the connection that backs the given streams *)
let terminate (ic, oc) =
Unix.shutdown (descr_of_out_channel oc) SHUTDOWN_ALL;
close_in_noerr ic;
close_out_noerr oc;;
let handle_client (ic, oc, addr) =
print_endline "Got new client!";;
let open Request in
let request = Request.read ic in
match request.uri with
| "/facts" ->
Response.make 200 "OK" "Facts." |> Response.write oc;
| "/graph" ->
Response.make 200 "OK" "Graph." |> Response.write oc;
| "/query" ->
Response.make 200 "OK" "Graph." |> Response.write oc;
| _ -> Response.make 404 "Not Found" "" |> Response.write oc;
terminate (ic, oc);;
let main port =
let tcp = (getprotobyname "tcp").p_proto in
let sock = socket PF_INET SOCK_STREAM tcp in
setsockopt sock SO_REUSEADDR true;
ADDR_INET (inet_addr_any, port) |> bind sock;
listen sock 10;
......@@ -24,4 +41,4 @@ let main port =
accept_loop () in
accept_loop ();;
main 80;;
main 8080;;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment