Skip to content

Commit d440dba

Browse files
committed
Start adding type structure to HTTP module
1 parent 47aea5b commit d440dba

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

.merlin

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
S src
12
B _build/src
23
PKG js_of_ocaml js_of_ocaml.ppx
3-
EXT js_of_ocaml
4+
EXT js

src/http.ml

+68-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,74 @@
1-
let port = Js.number_of_float 8080.0
1+
open Internal
2+
3+
type http_methods = Checkout
4+
| Connect
5+
| Copy
6+
| Delete
7+
| Get
8+
| Head
9+
| Lock
10+
| M_search
11+
| Merge
12+
| Mk_activity
13+
| Mk_calendar
14+
| Mk_col
15+
| Move
16+
| Notify
17+
| Options
18+
| Patch
19+
| Post
20+
| Propfind
21+
| Proppatch
22+
| Purge
23+
| Put
24+
| Report
25+
| Search
26+
| Subscribe
27+
| Trace
28+
| Unlock
29+
| Unsubscribe
30+
31+
let string_of_method = function
32+
| Checkout -> Js.string "checkout"
33+
| Connect -> Js.string "connect"
34+
| Copy -> Js.string "copy"
35+
| Delete-> Js.string "delete"
36+
| Get-> Js.string "get"
37+
| Head -> Js.string "head"
38+
| Lock -> Js.string "lock"
39+
| M_search -> Js.string "msearch"
40+
| Merge -> Js.string "merge"
41+
| Mk_activity -> Js.string "mkactivity"
42+
| Mk_calendar -> Js.string "mkcalendar"
43+
| Mk_col -> Js.string "mkcol"
44+
| Move-> Js.string "move"
45+
| Notify -> Js.string "notify"
46+
| Options -> Js.string "options"
47+
| Patch -> Js.string "patch"
48+
| Post -> Js.string "post"
49+
| Propfind -> Js.string "propfind"
50+
| Proppatch -> Js.string "proppatch"
51+
| Purge -> Js.string "purge"
52+
| Put-> Js.string "put"
53+
| Report -> Js.string "report"
54+
| Search -> Js.string "search"
55+
| Subscribe -> Js.string "subscribe"
56+
| Trace -> Js.string "trace"
57+
| Unlock -> Js.string "unlock"
58+
| Unsubscribe -> Js.string "unsubscribe"
259

3-
let http : Js.Unsafe.any Js.t =
4-
Js.Unsafe.fun_call
5-
(Js.Unsafe.js_expr "require")
6-
[| Js.Unsafe.inject (Js.string "http") |]
60+
class type http = object
61+
method methods : Js.js_string Js.js_array Js.readonly_prop
62+
end
63+
64+
let http () : http Js.t =
65+
Internal.require (Js.string "http")
66+
67+
let port = Js.number_of_float 8080.0
768

869
let handle_request (req: Js.Unsafe.any) (resp : Js.Unsafe.any) =
970
Js.Unsafe.meth_call resp "end" [|Js.string "It Works!" |> Js.Unsafe.inject|]
1071

1172
let server =
12-
Js.Unsafe.meth_call http "createServer" [|Js.Unsafe.inject handle_request|]
73+
Js.Unsafe.meth_call (http ()) "createServer"
74+
[|Js.Unsafe.inject handle_request|]

src/internal.ml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
let require (s : Js.js_string Js.t) =
3+
Js.Unsafe.fun_call (Js.Unsafe.js_expr "require") [|Js.Unsafe.inject s|]

src/nodejs.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
let node_version = "4.2.0"
12

23
module Http = struct
34
include Http
45
end
5-

0 commit comments

Comments
 (0)