Fork me on GitHub
#datomic
<
2020-08-22
>
Kevin Mungai10:08:58

Hi, I would like to use Datomic Cloud but I am having a hard time trying to figure out or (work out) how to create a web application that has routing. All the web applications I have created with Clojure just run after calling main and then accept http requests. These kind of web applications have no invokable function unlike what is suggested with Datomic Ions. How do I write a web application using routing libraries like bidi while exposing an invokable function via :http-direct ? Thanks in advance for your answers.

cjsauer02:08:48

The ion wraps (or adapts) the handler function. So for example, if you’re using bidi, then the handler that you get when you call bidi.ring/make-handler can be configured as an invokable function. This is thanks to http ions being “ring compatible” as per the docs. In the main function that you’re used to, you probably have been starting an http server (eg jetty) by passing it your handler function. With ions, you don’t run the http server yourself. This is abstracted away by API Gateway. All you have to do is define your handler function and configure it properly as an http direct endpoint.

cjsauer02:08:44

The gist is that, from this example in bidi’s readme, app is just a function (http request -> response). That is your invokable function. https://github.com/juxt/bidi#wrapping-as-a-ring-handler

Kevin Mungai14:08:41

I didn't know that you can just pass the handler as the invokable function to :http-direct. Thanks 👍.

jdhollis18:08:26

You can put the router in the ion that’s being invoked via :http-direct.

jdhollis18:08:02

Treat the ion like you would main.