4

Imagine some fellow wants to query a pizza server for the list of pizzas. This individual would do simply

 GET /pizzas
 ;=> ["cheese", "extra cheese", "broccoli"]

With pedestal-app's data model and messages, I am not sure how to design client-server communication. Here are the possibilities some minutes of hammocking brought:

  1. An effect-consumer that
    • transforms a message into an HTTP request
    • transforms back the results (to e.g. [{:type :add :topic [:pizzas] :value "cheese"} ...])
    • puts the messages in the queue
  2. A dedicated resource on the server (e.g. "/edn") that
    • accepts pedestal messages
    • dispatches to the right function
    • responds with the raw data (i.e. ["cheese", "extra cheese", "broccoli"])
    • has the effect-consumer transform back the results to messages
  3. A dedicated resource that uses the routes. Just like #2, but
    • altering the request
    • forwarding it to another entry in route table
  4. Messages on both sides, with
    • the server transforming messages into function calls
    • the server transforming results back into messages
    • the client just adding these messages to the queue

It seems to me that with approaches #2 and #4, I'd bypass and lose all the benefit of the interceptors. With approach #2, I'd need to redouble the routing logic. With approach #4, I'd also need to generate a lot of code to accommodate the pedestal client.

Options #1 and #3 seem better, but #3 smells hacky and #1, misdirected.

How are you guys doing it?

Thanks!

konr
  • 2,545
  • 2
  • 20
  • 38

1 Answers1

0

I don't know about pedestal, I've been working in ring/compojure/etc.

With ring you can trivially wrap things use ring.middleware.json and putting ring.middleware.json/wrap-json-response and ring.middleware.json/wrap-json-params around your pages, then inbound json data will be parsed into the parameters and you can return json as:

(ring.util.response/response ["cheese", "extra cheese", "broccoli"])

If your library doesn't support these kinds of behaviors you could probably extract the relevant code from ring etc.

DrLivingston
  • 788
  • 6
  • 15