Fork me on GitHub
#ring
<
2017-02-04
>
talexxx03:02:55

@weavejester True. I ended up using ring.middleware.basic-authentication

seancorfield04:02:36

@talexxx There's an amazing amount of middleware out there and it takes a while to navigate. I came to Clojure webs from a different tech where there was a lot of core built-in functionality and at first I thought I needed to write a lot of code myself... but as I read more about Ring and looked deeper into the middleware ecosystem, I found nearly everything was already available somewhere and just needed to be composed.

talexxx04:02:58

Good old FP

seancorfield04:02:47

Since then we've written our own middleware for a variety of things (such as New Relic transaction monitoring) and anything that is "common" across parts of our application.

isaac06:02:45

How can I let compojure destructure key instead of key_json from โ€/ticker_:key_jsonโ€

seancorfield06:02:46

You'd need to write a coercion function for that.

seancorfield06:02:46

so you'd write (GET "/ticker_:key" [key :<< from-json] my/handler) and from-json would parse JSON and produce either a data structure or nil if parsing failed ^ @isaac

isaac06:02:02

Thanks @seancorfield , I think compojure can not customize boundary of binding pattern, is it?

seancorfield06:02:52

Not sure what you mean?

isaac06:02:28

eg. (GET โ€œ/ticker_:{key}_json" [key :<< from-json] my/handler), {} as boudary

seancorfield06:02:24

Oh, I see... so you have /ticker_SOMETHING_json and you want the SOMETHING part?

seancorfield06:02:03

Hmm, that's tricky... I just simply wouldn't define an end point like that ๐Ÿ™‚

seancorfield06:02:18

/ticket/THING/json would be my preference

isaac06:02:31

Yeah, yourโ€™s suggestion is good, but I have some old apis, I must compatible with it.

seancorfield06:02:52

Sorry ๐Ÿ™‚

seancorfield06:02:07

Is there a limited set of things that key can be?

seancorfield06:02:38

If so, define all those routes to map to a single function that picks apart (:uri req) and "does the right thing".

seancorfield06:02:22

Otherwise /ticker_:key and map that to a handler and pick {X}_json apart dynamically...

isaac06:02:17

It seems that is best way. thank you, seancorfield

seancorfield07:02:46

It might be an interesting enhancement to routes tho', to accept :{thing}... you might consider a Pull Request to add that to Compojure?

isaac07:02:47

OK, i will try