|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var Fetch = require("../src/Fetch.js"); |
| 4 | +var Js_json = require("bs-platform/lib/js/js_json.js"); |
| 5 | +var Belt_Option = require("bs-platform/lib/js/belt_Option.js"); |
| 6 | +var Caml_option = require("bs-platform/lib/js/caml_option.js"); |
| 7 | + |
| 8 | +fetch("/api/hellos/1").then((function (prim) { |
| 9 | + return prim.text(); |
| 10 | + })).then((function (text) { |
| 11 | + return Promise.resolve((console.log(text), undefined)); |
| 12 | + })); |
| 13 | + |
| 14 | +fetch("/api/hello", Fetch.RequestInit.make(/* Post */2, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined)(undefined)).then((function (prim) { |
| 15 | + return prim.text(); |
| 16 | + })).then((function (text) { |
| 17 | + return Promise.resolve((console.log(text), undefined)); |
| 18 | + })); |
| 19 | + |
| 20 | +fetch("/api/fruit").then((function (prim) { |
| 21 | + return prim.json(); |
| 22 | + })).then((function (json) { |
| 23 | + return Promise.resolve(Js_json.decodeArray(json)); |
| 24 | + })).then((function (opt) { |
| 25 | + return Promise.resolve(Belt_Option.getExn(opt)); |
| 26 | + })).then((function (items) { |
| 27 | + return Promise.resolve(items.map((function (item) { |
| 28 | + return Belt_Option.getExn(Js_json.decodeString(item)); |
| 29 | + }))); |
| 30 | + })); |
| 31 | + |
| 32 | +var payload = { }; |
| 33 | + |
| 34 | +payload["hello"] = "world"; |
| 35 | + |
| 36 | +fetch("/api/hello", Fetch.RequestInit.make(/* Post */2, { |
| 37 | + "Content-Type": "application/json" |
| 38 | + }, Caml_option.some(JSON.stringify(payload)), undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined)(undefined)).then((function (prim) { |
| 39 | + return prim.json(); |
| 40 | + })); |
| 41 | + |
| 42 | +var formData = new FormData(); |
| 43 | + |
| 44 | +formData.append("image0", { |
| 45 | + type: "image/jpg", |
| 46 | + uri: "path/to/it", |
| 47 | + name: "image0.jpg" |
| 48 | + }, undefined); |
| 49 | + |
| 50 | +fetch("/api/upload", Fetch.RequestInit.make(/* Post */2, { |
| 51 | + Accept: "*" |
| 52 | + }, Caml_option.some(formData), undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined)(undefined)).then((function (prim) { |
| 53 | + return prim.json(); |
| 54 | + })); |
| 55 | + |
| 56 | +/* Not a pure module */ |
0 commit comments