(context-router context implementations)(context-router context implementations opts)Returns a [[reitit.ring/router]] defining routes that implement the
given rpcs. Use impl or impl-ext to specify the
implementations. The opts parameter is the same as for [[reitit.ring/router]].
(context-router my-api/context [(impl #'my-api/plus +)])
Important note: To use this, you need a transit parser middleware in your middleware chain, like muuntaja for example [https://github.com/metosin/reitit/blob/master/doc/ring/content_negotiation.md].
You can add this higher up, or via the opts parameter like
{:data {:muuntaja muuntaja.core/instance
:middleware [reitit.ring.middleware.muuntaja/format-middleware]}}
You will also need to add
[[reitit.ring.middleware.parameters/parameters-middleware]] to you
middlware chain. If you don't need it anywhere else in your
application, set it via the opts too:
{:data {:middleware [reitit.ring.middleware.parameters/parameters-middlware]}}
Returns a [[reitit.ring/router]] defining routes that implement the
given rpcs. Use [[impl]] or [[impl-ext]] to specify the
implementations. The `opts` parameter is the same as for [[reitit.ring/router]].
```
(context-router my-api/context [(impl #'my-api/plus +)])
```
Important note: To use this, you need a transit parser middleware in
your middleware chain, like muuntaja for example
[https://github.com/metosin/reitit/blob/master/doc/ring/content_negotiation.md].
You can add this higher up, or via the `opts` parameter like
```
{:data {:muuntaja muuntaja.core/instance
:middleware [reitit.ring.middleware.muuntaja/format-middleware]}}
```
You will also need to add
[[reitit.ring.middleware.parameters/parameters-middleware]] to you
middlware chain. If you don't need it anywhere else in your
application, set it via the `opts` too:
```
{:data {:middleware [reitit.ring.middleware.parameters/parameters-middlware]}}
```(impl rpc-var handler)Specifies an rpc implemtation as a function with the arguments and
return value exaclty as declared in the rpc declaration via
active.data.http.rpc/defn-rpc.
(impl #'my-api/plus +)
Specifies an rpc implemtation as a function with the arguments and return value exaclty as declared in the rpc declaration via [[active.data.http.rpc/defn-rpc]]. ``` (impl #'my-api/plus +) ```
(impl-ext rpc-var spec)Specifies an rpc implemtation as a ring handler spec, where the
:handler takes a request map and returning a response map. The
request map will contain an :args key, containing the list of
arguments of the rpc call, and must return the rpc result as the
:body in the response map.
(impl-ext #'my-api/plus
{:handler (fn [req]
{:status 200 :body (apply + (:args req))})})
Specifies an rpc implemtation as a ring handler spec, where the
`:handler` takes a request map and returning a response map. The
request map will contain an `:args` key, containing the list of
arguments of the rpc call, and must return the rpc result as the
`:body` in the response map.
```
(impl-ext #'my-api/plus
{:handler (fn [req]
{:status 200 :body (apply + (:args req))})})
```
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |