Fork me on GitHub

I have a core.async chan of database rows I’d like to return as my response body, but the content type should be transit+json and I’m not sure if it’s possible to encode the channel properly?


@jfntn Hmm… I think there are a couple of parts there. You should be able to set the Content-Type header directly in your response map.


There’s also an interceptor that should emit the correct encoding… one sec while I look it up.




What is the data type that the channel messages will be? You may need a transducer on the channel to turn a JDBC object into a map for the transit-json-body


So the chan will contain one map per row (from cassandra through the alia library). I should have added that I was hoping I could stream the response and have it end up on the client as a vector/collection


Ah, I see. But the whole collection of rows will never be a single data structure in memory, right?


That does complicate things.


My first attempt was to transduce the chan with transit/write but the client ends up reading the first map only


I can’t think of a really clean way to do it. You might be able to cheat a bit though.


If your transducer emits a \[ before the first row, and a \] after the last row, then the client will think it’s got a single collection.


I could accumulate the results in memory and return a data strucute just to get it to work now, but it’d be great to know whether this could be solved in the future since our responses will get bigger over time


@souenzzo you can map the extra information to route-name-extra map. Then you can get those extra information in any interceptor:

(def route-name-extra-map 
  {:route-name-a [...]})


nxqd: I'm using it. But on route will be way easier to see mistakes.


@mtnygard hmm let me try that


@mtnygard ah it works, but I need to interpose commas between rows


Is there a way to mount a route table into another one? so, if I have a defroutes in one namespace, and I want to mount all those routes at a particular path in the master service/routes table, how would I do that?


@cap10morgan You’ll have to defer expanding the routes, so just use def instead of defroutes. At that point, the route table is just data so you could update the path portion with a map and string concatenation


@mtnygard OK, thanks. Will play around with that.


@mtnygard When I tried this, I found that the repeated "/" at the root of my nested routes caused a double // to be required in the URL for the route to match more deeply-nested routes in the table (using the linear-search router). It did match that nested-root route, though. Does that seem like a bug?


And I'll add, print-routes only shows one / separating those path components, so at least that part of the system seems to consolidate them.


this is with 0.5.2