Found the problem, it was my code that misused yours, and due to the splitting, there were problems. I am now using an Api.elm without the splitting, but I will adapt the rest of the code to the splitting.
sss6elm/src/Api.elm | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/sss6elm/src/Api.elm b/sss6elm/src/Api.elm
index 50788c4..2337230 100644
--- a/sss6elm/src/Api.elm
+++ b/sss6elm/src/Api.elm
@@ -21,7 +21,7 @@ type Request a
{ method : String
, headers : List Http.Header
, basePath : String
- , pathParam : String
+ , pathParams : List String
, queryParams : List Url.Builder.QueryParameter
, body : Http.Body
, decoder : Json.Decode.Decoder a
@@ -36,7 +36,7 @@ request method path pathParams queryParams headerParams body decoder =
{ method = method
, headers = headers headerParams
, basePath = "http://localhost:5000"
- , pathParam = interpolatePath path pathParams
+ , pathParams = interpolatePath path pathParams
, queryParams = queries queryParams
, body = Maybe.withDefault Http.emptyBody (Maybe.map Http.jsonBody body)
, decoder = decoder
@@ -50,7 +50,7 @@ send toMsg (Request req) =
Http.request
{ method = req.method
, headers = req.headers
- , url = joinUrl req.basePath req.pathParam req.queryParams
+ , url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams
, body = req.body
, expect = Http.expectJson toMsg req.decoder
, timeout = req.timeout
@@ -64,7 +64,7 @@ map fn (Request req) =
{ method = req.method
, headers = req.headers
, basePath = req.basePath
- , pathParam = req.pathParam
+ , pathParams = req.pathParams
, queryParams = req.queryParams
, body = req.body
, decoder = Json.Decode.map fn req.decoder
@@ -107,19 +107,17 @@ headers =
List.filterMap (\( key, value ) -> Maybe.map (Http.header key) value)
-interpolatePath : String -> List ( String, String ) -> String
+interpolatePath : String -> List ( String, String ) -> List String
interpolatePath rawPath pathParams =
let
interpolate =
\( name, value ) path -> String.replace ("{" ++ name ++ "}") value path
in
List.foldl interpolate rawPath pathParams
+ |> String.split "/"
+ |> List.drop 1
queries : List ( String, Maybe String ) -> List Url.Builder.QueryParameter
queries =
List.filterMap (\( key, value ) -> Maybe.map (Url.Builder.string key) value)
-
-
-joinUrl prePath pathParam parameters =
- prePath ++ pathParam ++ Url.Builder.toQuery parameters