Fork me on GitHub
#reitit
<
2018-09-20
>
v3ga07:09:54

Could someone point me in the right direction with getting started with reitit and immutant? From the example it seemed like this would work. https://gist.github.com/titaniumbrella/eb99887315775e3f607219cb3e50b838

ikitommi08:09:02

@decim, reitit-http uses the interceptor-model and requires an interceptor executor to work. You can use pedestal or Sieppari, here’s with the latter one:

(ns user
  (:require [reitit.http :as http]
            [reitit.interceptor.sieppari :as sieppari]))

(def app
  (http/ring-handler
    (http/router
      [["/carbon" {:get {:handler (fn [_] {:status 200 :body "Carbonish 2.0"})}}]])
    {:executor sieppari/executor}))

;;-- Start Immutant web server -----------------------------
(defn start []
  "Start web server"
  (immutant.web/run #'app {:port 3333})
  (println "SERVER: STARTED!"))

(defn stop []
  "Stop web server"
  (immutant.web/stop)
  (println "SERVER: STOPPED!"))

ikitommi08:09:40

the default web/run calls the handler synchronously, so it’s blocking despite you using manifold, core.async or some other. I have a Immutant3.0 branch somewhere, which has the :async? option like jetty does.

ikitommi08:09:49

(it’s also 2x faster)

ikitommi08:09:33

e.g. you should cann the app with 3 arguments: request, on-success and on-failure.

v3ga08:09:47

@ikitommi hmm ahh i see. i’m afraid to take on pedestal as i’m fairly new but i do have a friend that uses it. what if i went with reitit.ring instead?

ikitommi08:09:13

yes, reitit-ring is a good option for today.

ikitommi08:09:39

I have many PRs on the web servers & ring to get built-in support for NIO & async, might take some time to get all in. Someone should make a good abstraction over web servers, so that one could change easily between aleph, immutant, jetty etc. e.g. common way to go async, maybe websockets too. Pedestal has something like this, but it’s kinda separate island (of everything)

v3ga08:09:00

hmm i see. That sort of confused me. Both reitit and pedestal are used for routing so what do you get from combining the two?

v3ga08:09:24

i’ve actually been trying to separate the differences all night.

ikitommi08:09:03

pedestal + reitit is just a example, mainly to show that it can be done and for those that have already invested in pedestal and would add things like swagger & coercion into their apps.

ikitommi08:09:35

reitit-ring is for ring-users, reitit-http is bit rough (sieppari has version 0.0.0-alpha5 out), but I think it’s a stack for the future. Good thing is that the route syntax is same for all, should be possible to start with one and port to another later.

ikitommi08:09:18

we are currently using reitit-ring in the projects (and compojure-api and others for many older ones).

v3ga08:09:41

I see. so say i switched over to ring/ring-handler… i would think that that would just work as is, no? https://gist.github.com/titaniumbrella/c4b85d952bf015aec0f9cbe6fa7ce2bf

v3ga08:09:24

and i appreciate this…now i’m at least in the ballpark. I had no idea what I was truly looking at as far as choosing ‘http’ over ring

ikitommi08:09:03

the app should be:

(def app
  (ring/ring-handler
    (ring/router
      [(routes)])
    (ring/create-default-handler)))

ikitommi08:09:14

e.g. the routes is a function and needs to be called.

ikitommi08:09:45

or with values:

(def routes
  ["/carbon" {:get home-page}])

(def app
  (ring/ring-handler
    (ring/router
      routes)
    (ring/create-default-handler)))

ikitommi08:09:50

you can nest routes in extra vectors if you like, the are flattened by the route compiler.

v3ga08:09:36

odd, i tried that and it threw a null pointer error on the (ring/router line)

ikitommi08:09:23

maybe a dirty repl state? Works here ok.

v3ga08:09:57

hmm really not sure. i just restarted my repl and i’m experiencing the same thing. Here’s my project.clj. I assume we’re using the same versioning or similar enough. https://gist.github.com/titaniumbrella/ad9409605d5cc8a7c21ddea93dec1723

orestis08:09:43

@decim for me the main thing about pedestal is that it claims it’s production-ready, with logging already setup, some common-sense security middleware/interceptors already setup for you, and of course the interceptor chain which is a very very powerful concept. I haven’t looked closely to anything else in pure ring land though so I may be missing something.

v3ga09:09:21

@orestis yeah i wouldn’t mind giving pedestal a go but if i’m already having trouble with immutant it’s most likely going to be more of a set back for now

orestis09:09:44

Pedestal supports immutant as a backend, even though the default template uses jetty.

orestis09:09:51

I haven’t used immutant yet though.

v3ga09:09:12

i’ll take a look