summaryrefslogtreecommitdiff
path: root/elm/Lib/Api.elm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-01-05 12:47:04 +0100
committerYorhel <git@yorhel.nl>2020-01-05 12:52:12 +0100
commitd1d981efa5b0910260cbd1c226e3ab683c8304ae (patch)
tree8704fd96dc8e5820dae8017e5bfaf882ed80980f /elm/Lib/Api.elm
parent0efea750ac26629f48fb50a9cdc9d71bd08257b7 (diff)
refactor: Combine json_api() & elm_form() + generate Elm function to msg API endpoint
The new elm_api() function now creates an API endpoint (like json_api()) and generates a corresponding Elm module to interact with that API (like elm_form()). The API endpoint URL is now derived from the name of the Elm module, so there's no need to think of a separate URL and less prone to making typos when using that URL from Elm. Reduces the boilerplace a bit as well.
Diffstat (limited to 'elm/Lib/Api.elm')
-rw-r--r--elm/Lib/Api.elm7
1 files changed, 4 insertions, 3 deletions
diff --git a/elm/Lib/Api.elm b/elm/Lib/Api.elm
index ae900fe5..112dcc81 100644
--- a/elm/Lib/Api.elm
+++ b/elm/Lib/Api.elm
@@ -55,11 +55,12 @@ expectResponse msg =
in Http.expectJson res decode
--- Send a POST request with a JSON body to the VNDB API and get a Response back.
+-- Send a POST request to a Perl `elm_api` endpoint
+-- Should not be used directly, use the `send` function in the appropriate Gen.FormName module instead.
post : String -> JE.Value -> (Response -> msg) -> Cmd msg
-post url body msg =
+post name body msg =
Http.post
- { url = url
+ { url = "/elm/" ++ name ++ ".json"
, body = Http.jsonBody body
, expect = expectResponse msg
}