Skip to content

Commit 12db23a

Browse files
author
SGrondin
committed
Improved OCaml http methods
1 parent bbe18de commit 12db23a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎src/targets/ocaml/cohttp.js‎

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

10+
var methods = ['get', 'post', 'head', 'delete', 'patch', 'put', 'options'];
1011
var code = [];
1112

1213
code.push('open Cohttp_lwt_unix');
@@ -46,7 +47,7 @@ module.exports = function (options) {
4647

4748
if (bodyPresent) {
4849
// Just text
49-
code.push(util.format('let body = Cohttp_lwt_unix.of_string %s in', JSON.stringify(this.source.postData.text)));
50+
code.push(util.format('let body = Cohttp_lwt_body.of_string %s in', JSON.stringify(this.source.postData.text)));
5051
} else if (this.source.postData && !this.source.postData.text && this.source.postData.params && this.source.postData.params.length) {
5152
// Post params
5253
bodyPresent = true;
@@ -55,16 +56,16 @@ module.exports = function (options) {
5556
return param.name + '=' + param.value;
5657
}).join('&');
5758

58-
code.push(util.format('let body = Cohttp_lwt_unix.of_string "%s" in', body));
59+
code.push(util.format('let body = Cohttp_lwt_body.of_string "%s" in', body));
5960
}
6061

6162
// Do the request
6263
code.push('');
6364

64-
code.push(util.format('Client.call %s%s(Code.method_of_string "%s") uri',
65+
code.push(util.format('Client.call %s%s%s uri',
6566
(headersPresent || cookiesPresent) ? '~headers ' : '',
6667
bodyPresent ? '~body ' : '',
67-
this.source.method
68+
(methods.indexOf(this.source.method.toLowerCase()) >= 0 ? ('`' + this.source.method.toUpperCase()) : '(Code.method_of_string "' + this.source.method + '")')
6869
));
6970

7071
// Catch result

0 commit comments

Comments
 (0)