oliyh / martian

The HTTP abstraction library for Clojure/script, supporting OpenAPI, Swagger, Schema, re-frame and more

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unclear how to use query-params when bootstrapping without openapi/swagger

vemv opened this issue · comments

commented

Hey there again,

I tried to build a URL which API currently (apparently) lacks a openapi/swagger definition.

This was my attempt:

(def open-meteo-api
  (delay
    (http-lite/bootstrap "https://archive-api.open-meteo.com/v1"
                         [{:route-name :forecast
                           :path-parts ["/forecast"]
                           :method     :get
                           :query-params {:latitude      s/Num
                                          :longitude     s/Num
                                          :daily         #{"precipitation_sum"}
                                          :past-days     s/Int
                                          :forecast-days s/Int
                                          :timezone      #{"Europe/Berlin"}}}])))

(comment
  (martian/url-for @open-meteo-api
                   :forecast
                   {:latitude      "41.47"
                    :longitude     "2.09"
                    :daily         "precipitation_sum"
                    :past-days     "7"
                    :forecast-days "1"
                    :timezone      "Europe/Berlin"}))

...it resulted in "https://archive-api.open-meteo.com/v1/forecast" without query params.

What's the correct incantation?

Thanks - V

Hello,

url-for does not include query params. You can instead use request-for and build the url with query yourself.

Possibly a use case for a function called url+query-for?

commented

Thanks for the response!

Hmm, from the two first paragraphs in https://github.com/oliyh/martian/tree/22605e74acdc7101b6226b8cb023055eb22aea97#martian , I thought the project seeked to abstract one from this sort of things.

e.g. what is expressed as :query-params today may become :body-params tomorrow, when an API changes from v1 to v2.

WDYT?

Yes I think I agree, as query strings are part of urls. I'm only hesitant because it would be a breaking API change.

commented

It might be worthwhile to create a v2 namespace. But tbh I'm just assessing this lib, so I don't have any pressing force for the api to be this or that way.

Cheers - V

commented

Nice!

It's an option you can turn on in url-for, I thought that was the best compromise