pedestal

lwhorton 2019-01-04T20:32:19.009600Z

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})

lwhorton 2019-01-04T20:33:19.010500Z

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 😕

2019-01-04T20:49:54.010700Z

@lwhorton 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…)

2019-01-04T20:52:34.010900Z

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

2019-01-04T20:53:52.011100Z

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]})

2019-01-04T20:54:48.011300Z

refer to https://github.com/pedestal/pedestal-docs/issues/66

2019-01-04T20:54:52.011600Z

I need to update the docs

ccann 2019-01-04T20:55:13.011800Z

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

lwhorton 2019-01-04T20:57:11.012Z

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

2019-01-04T21:11:49.012200Z

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.

lwhorton 2019-01-04T21:12:57.012400Z

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

2019-01-04T21:18:17.012600Z

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.