Liking cljdoc? Tell your friends :D

active.data.http.rpc.reitit


context-routerclj

(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]}}
```
sourceraw docstring

implclj

(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 +)
  ```
  
sourceraw docstring

impl-extclj

(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))})})
```
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close