Skip to content

Commit 2ef7b65

Browse files
author
SGrondin
committed
Many updates to OCaml
1 parent fd0583f commit 2ef7b65

11 files changed

Lines changed: 27 additions & 17 deletions

File tree

src/targets/ocaml/cohttp.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ module.exports = function (source, options) {
77
indent: ' '
88
}, options)
99

10-
var methods = ['get', 'post', 'head', 'delete', 'patch', 'put', 'options'];
11-
var code = [];
10+
var methods = ['get', 'post', 'head', 'delete', 'patch', 'put', 'options']
11+
var code = []
1212

13-
code.push('open Cohttp_lwt_unix');
14-
code.push('open Cohttp');
15-
code.push('open Lwt');
16-
code.push('');
13+
code.push('open Cohttp_lwt_unix')
14+
code.push('open Cohttp')
15+
code.push('open Lwt')
16+
code.push('')
1717

1818
// Create URI
1919
code.push(util.format('let uri = Uri.of_string "%s" in', source.fullUrl))
@@ -44,7 +44,7 @@ module.exports = function (source, options) {
4444
headers.length ? '~headers ' : '',
4545
source.postData.text ? '~body ' : '',
4646
(methods.indexOf(this.source.method.toLowerCase()) >= 0 ? ('`' + this.source.method.toUpperCase()) : '(Code.method_of_string "' + this.source.method + '")')
47-
));
47+
))
4848

4949
// Catch result
5050
code.push('>>= fun (res, body_stream) ->')
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
open Cohttp_lwt_unix
2+
open Cohttp
23
open Lwt
34

45
let uri = Uri.of_string "http://mockbin.com/har" in
@@ -7,6 +8,6 @@ let headers = Header.init ()
78
in
89
let body = "foo=bar&hello=world" in
910

10-
Client.call ~headers ~body (Code.method_of_string "POST") uri
11+
Client.call ~headers ~body `POST uri
1112
>>= fun (res, body_stream) ->
1213
(* Do stuff with the result *)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
open Cohttp_lwt_unix
2+
open Cohttp
23
open Lwt
34

45
let uri = Uri.of_string "http://mockbin.com/har" in
@@ -7,6 +8,6 @@ let headers = Header.init ()
78
in
89
let body = "{\"number\": 1, \"string\": \"f\\\"oo\", \"arr\": [1, 2, 3], \"nested\": {\"a\": \"b\"}, \"arr_mix\": [1, \"a\", {\"arr_mix_nested\": {}}] }" in
910

10-
Client.call ~headers ~body (Code.method_of_string "POST") uri
11+
Client.call ~headers ~body `POST uri
1112
>>= fun (res, body_stream) ->
1213
(* Do stuff with the result *)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
open Cohttp_lwt_unix
2+
open Cohttp
23
open Lwt
34

45
let uri = Uri.of_string "http://mockbin.com/har" in
56
let headers = Header.init ()
67
|> fun h -> Header.add h "cookie" "foo=bar; bar=baz"
78
in
89

9-
Client.call ~headers (Code.method_of_string "POST") uri
10+
Client.call ~headers `POST uri
1011
>>= fun (res, body_stream) ->
1112
(* Do stuff with the result *)

test/fixtures/output/ocaml/cohttp/full.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
open Cohttp_lwt_unix
2+
open Cohttp
23
open Lwt
34

45
let uri = Uri.of_string "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value" in
@@ -9,6 +10,6 @@ let headers = Header.init ()
910
in
1011
let body = "foo=bar" in
1112

12-
Client.call ~headers ~body (Code.method_of_string "POST") uri
13+
Client.call ~headers ~body `POST uri
1314
>>= fun (res, body_stream) ->
1415
(* Do stuff with the result *)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
open Cohttp_lwt_unix
2+
open Cohttp
23
open Lwt
34

45
let uri = Uri.of_string "http://mockbin.com/har" in
@@ -7,6 +8,6 @@ let headers = Header.init ()
78
|> fun h -> Header.add h "x-foo" "Bar"
89
in
910

10-
Client.call ~headers (Code.method_of_string "GET") uri
11+
Client.call ~headers `GET uri
1112
>>= fun (res, body_stream) ->
1213
(* Do stuff with the result *)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
open Cohttp_lwt_unix
2+
open Cohttp
23
open Lwt
34

45
let uri = Uri.of_string "http://mockbin.com/har" in
@@ -7,6 +8,6 @@ let headers = Header.init ()
78
in
89
let body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--" in
910

10-
Client.call ~headers ~body (Code.method_of_string "POST") uri
11+
Client.call ~headers ~body `POST uri
1112
>>= fun (res, body_stream) ->
1213
(* Do stuff with the result *)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
open Cohttp_lwt_unix
2+
open Cohttp
23
open Lwt
34

45
let uri = Uri.of_string "http://mockbin.com/har" in
@@ -7,6 +8,6 @@ let headers = Header.init ()
78
in
89
let body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--" in
910

10-
Client.call ~headers ~body (Code.method_of_string "POST") uri
11+
Client.call ~headers ~body `POST uri
1112
>>= fun (res, body_stream) ->
1213
(* Do stuff with the result *)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
open Cohttp_lwt_unix
2+
open Cohttp
23
open Lwt
34

45
let uri = Uri.of_string "http://mockbin.com/har" in
@@ -7,6 +8,6 @@ let headers = Header.init ()
78
in
89
let body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--" in
910

10-
Client.call ~headers ~body (Code.method_of_string "POST") uri
11+
Client.call ~headers ~body `POST uri
1112
>>= fun (res, body_stream) ->
1213
(* Do stuff with the result *)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
open Cohttp_lwt_unix
2+
open Cohttp
23
open Lwt
34

45
let uri = Uri.of_string "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value" in
56

6-
Client.call (Code.method_of_string "GET") uri
7+
Client.call `GET uri
78
>>= fun (res, body_stream) ->
89
(* Do stuff with the result *)

0 commit comments

Comments
 (0)