Fork me on GitHub
#pedestal
<
2019-01-04
>
lwhorton20:01:19

hmm. i’m playing around with pedestal and failing at pretty much step one. what the heck is going on here?

(defn index [req]
  {:status 200
   :body "hi"})

(def routes
  (route/expand-routes
    #{["/foo" :get index :route-name :index]}))

(http/create-server {:routes routes
                       :type :jetty
                       :port port})

ddeaguiar20:01:54

@U0W0JDY4C can you point me to the docs you are following? The service map keys need to be fully-qualified keywords (i.e., io.pedestal.http/routes or, if you have io.pedestal.http aliased to something like http then ::http/routes, etc…)

ddeaguiar20:01:34

I’d also assoc ::http/join? false to the service map when so that you can stop the server when running from a repl

ddeaguiar20:01:52

Finally, I’d not invoke expand-routes directly. That’s done for you by the io.pedestal.http/default-interceptors fn when create-server is invoked. Your routes should instead be

(def routes
   #{["/foo" :get `index :route-name :index]})

ddeaguiar20:01:52

I need to update the docs

ccann20:01:13

> Finally, I’d not invoke expand-routes directly. good to know

lwhorton20:01:11

:thumbsup: i was working off the http://pedastal.io/guides , but i see now that the ::http/ was missing

ddeaguiar21:01:49

Just an FYI, I went back and looked at the source and you can call pass in routes expanded by expand-routes. Not sure what issue I ran into when I created that Github issue ages ago but I do still think you should let Pedestal’s internals expand routes for you unless you are explicitly not leveraging the defaults provided by io.pedestal.http/default-interceptors.

lwhorton21:01:57

i’m still poking around the interceptor stuff, checking out content negotiation and coersion etc.. the whole thing looks like a great paradigm

ddeaguiar21:01:17

Interceptors are great. The core set of interceptors provided by Pedestal is intentionally kept small. Application-specific needs can be implemented as interceptors pretty easily.

lwhorton20:01:19

the create-server fails with `Execution error (IllegalArgumentException) at io.pedestal.http.route/eval13846$fn$G (route.clj:426). No implementation of method: :router-spec of protocol: #’io.pedestal.http.route/RouterSpecification found for class: nil`. not really sure what this means without digging into src, but so far just following the tutorial / docs has gotten me to here 😕