This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-01
Channels
- # aleph (2)
- # announcements (3)
- # architecture (9)
- # babashka (56)
- # beginners (18)
- # calva (7)
- # catalyst (16)
- # cider (18)
- # cljfx (3)
- # cljs-dev (23)
- # clojure-europe (11)
- # clojure-hungary (1)
- # clojure-nl (2)
- # clojure-norway (24)
- # clojure-sweden (2)
- # clojurescript (37)
- # code-reviews (47)
- # datalog (3)
- # datomic (8)
- # emacs (11)
- # events (2)
- # graalvm (7)
- # gratitude (1)
- # hyperfiddle (12)
- # java (1)
- # jvm (46)
- # kaocha (3)
- # lsp (3)
- # malli (4)
- # matcher-combinators (1)
- # music (1)
- # nbb (1)
- # nrepl (4)
- # releases (1)
- # sci (15)
- # shadow-cljs (21)
- # slack-help (21)
- # tools-deps (17)
Hi, having just watch the "talking to martians" talk, I was wondering which of the list of libraries of martian you would use with BB?
https://cljdoc.org/d/com.github.oliyh/martian-babashka-http-client/0.1.25/doc/readme
@U4C3ZU6KX I tested this and it works:
(babashka.deps/add-deps '{:deps {com.github.oliyh/martian-babashka-http-client {:mvn/version "0.1.25"}}})
I have sort of got it working, but I have hit the normal issues of :insecure (I have tried to add a client into the ctx but not sure if that is the correct way to handle it. Also I am getting errors, from the library and I was wondering where I could ask questions. Can't find a #martian channel.
The author is @U076R6N1L - perhaps we can ask him to create a martian channel, but feel free to continue here as well. As for creating a separate client, makes sense. Let's have a look at the source...
@U4C3ZU6KX If you would add :client
here:
https://github.com/oliyh/martian/blob/2540b6273b32a099ce9632a68115c6d83da83890/babashka-http-client/src/martian/babashka/http_client.clj#L13
then a custom client would work
I think you would need to pass ctx
as well and add :client
from ctx
to the request map
@U4C3ZU6KX you could experiment locally with this and use the martian "plugin" as a :local/root
project in in bb.edn
, let me know if you need any help
Hi, I can have a look at this a bit later on. There is no #martian channel, happy to chat on this thread
@U076R6N1L one issue is that the README of the martian project does not list:
com.github.oliyh/martian-babashka-http-client
as a clojars dependencythe other issue, being able to pass a custom client, is another one. not sure if you've done something similar for the other clients?
yes, but also a concept that is known to other http libraries like http-kit and clj-http
I have a DM with @U4C3ZU6KX but will share the answer back here once we've got it sorted
with the clj-http you can pass "load-opts" which get later merged when doing a request. https://github.com/oliyh/martian/blob/2540b6273b32a099ce9632a68115c6d83da83890/clj-http/src/martian/clj_http.clj#L22-L31 This would also be a good solution for the bb client lib
The entire request map in the context is passed to the http library, so you can write an interceptor to put anything you want in there
Yeah, that's why load opts is special, because that happens before you have an instance, therefore no interceptors yet
I need to check if all the other ones work the same way, they should. And yes, that's how you do it for loading the swagger json. After that, you can write an interceptor like this
(fn [ctx]
(assoc-in ctx [:request :client] your-client-thing))
Perhaps adding some docs about this would be good, if you can verify that it works for you
I still get
; clojure.lang.ExceptionInfo: unable to find valid certification path to requested target mexp.core tripod/context.cljc:207:7
The snippet from my code
(def client (http/client (assoc-in http/default-client-opts [:ssl-context :insecure] true)))
(def allow-insecure
{:name ::allow-insecure
:enter (fn [ctx]
(assoc-in ctx [:request :client] client))})
(def add-authentication-header
{:name ::add-authentication-header
:enter (fn [ctx]
(assoc-in ctx [:request :headers "Authorization"] "Token: <token str>" ))})
(def m (martian/bootstrap-openapi (str "https://" (:cpd-route (u/get_config (u/get-user))) "/api/v2/catalog")
(mf/load-local-resource "resources/descriptors.yaml")
{:interceptors (concat martian/default-interceptors
[add-authentication-header
allow-insecure
martian-http/perform-request])}))
(martian/response-for m :get-descriptors)
output:
No matching content-type available {:supported-content-types #{}, :available-content-types (application/json), :header Content-Type}
No matching content-type available {:supported-content-types #{}, :available-content-types (application/json), :header Content-Type}
; clojure.lang.ExceptionInfo: Exceptional status code: 404 mexp.core tripod/context.cljc:207:7
https://github.com/oliyh/martian/blob/2540b6273b32a099ce9632a68115c6d83da83890/babashka-http-client/src/martian/babashka/http_client.clj#L91 the last argument
When adding it through the interceptor I no longer get the message about the certificates, but I get a 404 which means I got through. so the following seemed to work ok
{:name ::allow-insecure
:enter (fn [ctx]
(assoc-in ctx [:request :client] client))})
Putting the client on the end of the load-opts did not work I got the error about the certs.
Thank you for your persistence. very much appreciated. Have a good rest of the evening.The http-kit client should also work with bb btw and clj-http-lite as well, so you have more options.
as @U076R6N1L suggested, just trying to load the swagger docs using a bare minimal example using only the client might be good to try
That @U04V15CAJ, I am afraid I could not get the Authentication to work with the martian-babashka-http library so I swap to clj-http-lite and it works. The insecure set up with the client worked, so that was good. Just struggle to get oauth token injected. I wish I understood more to take load off you. Hope you have a good weekend.
i updated the martian readme to hopefully make the http-client library choice easier to understand: https://github.com/oliyh/martian/blob/master/README.md