Fork me on GitHub
#reitit
<
2022-01-06
>
pinkfrog13:01:06

How can I let this route match the url /api/ping which doesn’t contain the id part? And in this case, the desirable id value would be “”.

(def router
    (r/router
     [["/api/ping/:id" ::ping]]))

dharrigan15:01:43

Maybe this might help?

dharrigan15:01:01

This would match "/api/starships" and "/api/starships/:id"

dharrigan15:01:30

so if you put your ping as a separate route, then with "" and "/:id" nested underneath

nickbauman20:01:40

Hi can anyone point me to the documentation of reitit.ring.coercion? I want to inspect a header with it.

geraldodev23:01:19

curl -X 'POST' \
  '' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{"success": "bar"}'
clojure.lang.ExceptionInfo: clojure.lang.ExceptionInfo in Interceptor :reitit.http.interceptors.muuntaja/format-response - Malformed application/json in :muuntaja/encode
{:execution-id 10, :stage :leave, :interceptor :reitit.http.interceptors.muuntaja/format-response, :exception-type :clojure.lang.ExceptionInfo, :exception #error {
 :cause "No serializer found for class reitit.coercion.spec$create$reify__43032 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: clojure.lang.PersistentHashMap[\":exception\"]->clojure.lang.ExceptionInfo[\"data\"]->clojure.lang.PersistentArrayMap[\":coercion\"])"
I'm having this message in pedestal-swagger example with a post handler
["/custom-gql"
            {:post {:handler (fn [ctx]
                               {:foo :bar})
                    :parameters {:body string?}}}]
Do you have idea what is the root cause ?

delaguardo12:01:43

Your handler should return ring response. Try to wrap like this {:status 200 :body {:foo :bar}}

geraldodev18:01:12

I've changed to, and it remains. The message says muuntaja/format-response , I've tried to find the message on muuntaja code, I rly don't know what is happening. Probably something awful on my part. To eliminate that I've introduced this handle in pedestal-swagger example, and the result is similar

["/custom-gql"
            {:post {:handler
                    (fn [ctx]
                      {:status 200 :body
                       {"foo" "bar"}})
                    :parameters {:body string?}}}]

dharrigan19:01:24

Would it be the case that your body is spec'ed out to be a string, but you're sending a JSON object that Jackson is trying to deseralise as foo with a value of bar, i.e., a map like structure?

dharrigan19:01:56

so Jackson is failing to deserialize and thus can't find any thing resembling a (java) bean

dharrigan19:01:49

would it work if you spec it out like this?

dharrigan19:01:10

....`:parameters {:body {:foo string?}}`

geraldodev20:01:06

i've introduced parameters :body string? to send a string to the server, the error happen on leave stage so It does not look like it. I'm changing to :body any? to see what happens

geraldodev20:01:05

@U11EL3P9U man you are right! thank you.

dharrigan21:01:22

no problemo! Glad it's working now for you. 🙂

geraldodev18:01:12
replied to a thread: curl -X 'POST' \ '<http://localhost:8080/custom-gql>' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{"success": "bar"}' clojure.lang.ExceptionInfo: clojure.lang.ExceptionInfo in Interceptor :reitit.http.interceptors.muuntaja/format-response - Malformed application/json in :muuntaja/encode {:execution-id 10, :stage :leave, :interceptor :reitit.http.interceptors.muuntaja/format-response, :exception-type :clojure.lang.ExceptionInfo, :exception #error { :cause "No serializer found for class reitit.coercion.spec$create$reify__43032 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: clojure.lang.PersistentHashMap[\":exception\"]-&gt;clojure.lang.ExceptionInfo[\"data\"]-&gt;clojure.lang.PersistentArrayMap[\":coercion\"])" I'm having this message in pedestal-swagger example with a post handler ["/custom-gql" {:post {:handler (fn [ctx] {:foo :bar}) :parameters {:body string?}}}] Do you have idea what is the root cause ?

I've changed to, and it remains. The message says muuntaja/format-response , I've tried to find the message on muuntaja code, I rly don't know what is happening. Probably something awful on my part. To eliminate that I've introduced this handle in pedestal-swagger example, and the result is similar

["/custom-gql"
            {:post {:handler
                    (fn [ctx]
                      {:status 200 :body
                       {"foo" "bar"}})
                    :parameters {:body string?}}}]