|
| 1 | +// Generated by ReScript, PLEASE EDIT WITH CARE |
| 2 | + |
| 3 | +import * as Curry from "rescript/lib/es6/curry.js"; |
| 4 | +import * as Axios from "axios"; |
| 5 | +import * as Js_exn from "rescript/lib/es6/js_exn.js"; |
| 6 | +import ReactOnRails from "react-on-rails"; |
| 7 | +import * as Json$JsonCombinators from "@glennsl/rescript-json-combinators/src/Json.bs.mjs"; |
| 8 | +import * as Json_Decode$JsonCombinators from "@glennsl/rescript-json-combinators/src/Json_Decode.bs.mjs"; |
| 9 | + |
| 10 | +async function fetchComments(param) { |
| 11 | + var response = await fetch("comments.json"); |
| 12 | + var jsonRes = await response.json(); |
| 13 | + var jsonComment = Json_Decode$JsonCombinators.object(function (field) { |
| 14 | + return { |
| 15 | + author: field.required("author", Json_Decode$JsonCombinators.string), |
| 16 | + text: field.required("text", Json_Decode$JsonCombinators.string), |
| 17 | + id: field.required("id", Json_Decode$JsonCombinators.$$int) |
| 18 | + }; |
| 19 | + }); |
| 20 | + var jsonComments = Json_Decode$JsonCombinators.object(function (field) { |
| 21 | + return { |
| 22 | + comments: field.required("comments", Json_Decode$JsonCombinators.array(jsonComment)) |
| 23 | + }; |
| 24 | + }); |
| 25 | + var decodedRes = Json$JsonCombinators.decode(jsonRes, jsonComments); |
| 26 | + if (decodedRes.TAG === /* Ok */0) { |
| 27 | + return decodedRes._0.comments; |
| 28 | + } else { |
| 29 | + return Js_exn.raiseError(decodedRes._0); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +async function storeComment(author, text) { |
| 34 | + await Axios.post("comments.json", { |
| 35 | + author: author, |
| 36 | + text: text |
| 37 | + }, { |
| 38 | + responseType: "json", |
| 39 | + headers: Curry._1(ReactOnRails.default.authenticityHeaders, undefined) |
| 40 | + }); |
| 41 | +} |
| 42 | + |
| 43 | +var Api = { |
| 44 | + fetchComments: fetchComments, |
| 45 | + storeComment: storeComment |
| 46 | +}; |
| 47 | + |
| 48 | +export { |
| 49 | + Api , |
| 50 | +} |
| 51 | +/* axios Not a pure module */ |
0 commit comments