Fork me on GitHub
#pedestal
<
2017-05-25
>
jfntn14:05:10

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?

mtnygard14:05:31

@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.

mtnygard14:05:52

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

mtnygard14:05:33

io.pedestal.http/transit-json-body

mtnygard14:05:20

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

jfntn14:05:42

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

mtnygard14:05:44

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

mtnygard14:05:56

That does complicate things.

jfntn14:05:44

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

mtnygard14:05:04

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

mtnygard14:05:31

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.

jfntn14:05:33

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

jimmy14:05:33

@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 [...]})

souenzzo15:05:53

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

jfntn14:05:03

@mtnygard hmm let me try that

jfntn15:05:35

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

cap10morgan16:05:26

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?

mtnygard16:05:37

@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

cap10morgan16:05:08

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

cap10morgan18:05:11

@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?

cap10morgan18:05:37

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.

cap10morgan18:05:06

this is with 0.5.2