Self documenting API specifications

  1. Provide a list of input fields and button that would allow to test the API and have their payload going through the Elm decoders
  2. Read the Elm source code and display on the page the significant part (Decoders and Types)
<pre id="decoders"></pre>
<pre id="types"></pre>
<script type="text/javascript">
(function() {
function readTextFile(file, fn) {
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function() {
if (rawFile.readyState === 4) {
if (rawFile.status === 200 || rawFile.status === 0) {
var allText = rawFile.responseText;
return fn(allText);
}
}
};
rawFile.send(null);
}
readTextFile("/source/scripts/helpers/types.elm", function(allText) {
document.getElementById('types').innerHTML = allText.match(/-- DATA[\s\S]*/)[0];
});
readTextFile("/source/scripts/helpers/decoders.elm", function(allText) {
document.getElementById('decoders').innerHTML = allText.match(/-- DATA[\s\S]*/)[0];
});
})();
</script>
module Helpers.Decoders exposing (..)import Json.Decode as Decode exposing (Decoder)
import Helpers.Types as Types
-- DATA DECODERS --originDecoder : Decoder Types.Origin
originDecoder =
Decode.at [ "origin" ] Decode.string

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store