Fork me on GitHub
#yada
<
2015-10-07
>
stijn07:10:58

hi @malcolmsparks, I'm impressed with what yada has become after we last spoke at EuroClojure simple_smile

malcolmsparks10:10:37

@stijn: thanks - @ordnungswidrig pushed me to refactor the core.clj and it took on a simpler form as a result.

malcolmsparks13:10:46

@ordnungswidrig: not sure what that means, I need to go on an emoticons course...

ordnungswidrig13:10:13

That pictures a human being raising it’s arm to celebrate joy.

ordnungswidrig13:10:44

LOL. I actually read „emotions course“ and thought: indeed, that’s the english people.

malcolmsparks13:10:52

I can see the \o/ person now. I spent years typing simple_smile to indicate smiling before I realised that if you look at it sideways you can see a smiling face.

malcolmsparks13:10:38

(and that was before computer terminals replaced your ASCII with pictures, of course)

malcolmsparks13:10:42

like slack just did

ordnungswidrig13:10:43

Oh, that supports my theory on english people

ordnungswidrig13:10:52

…and emotions

malcolmsparks13:10:04

you mean that we're stupid?

malcolmsparks13:10:21

I partially agree

ordnungswidrig13:10:18

I meant, english people are reserved, except after the pub or at sports. That’s what I learned from german television

malcolmsparks13:10:26

that basically sums up english people - you've nailed it

mccraigmccraig13:10:14

i used to think brits were reserved, then i lived in norway for a few years

mccraigmccraig13:10:42

now i think there is a continuum of reservation which starts at the north pole and decreases as you approach the equator

malcolmsparks13:10:11

except it flips over across Great Britain

malcolmsparks13:10:41

well, I mean England really, the Scots are well..

mccraigmccraig13:10:16

ha, well kinda - northerners are better at saying hello in the street, but when it comes to actual emotions, not so much (and i have 46 years of experience with being a northerner, so i can say that)

malcolmsparks13:10:49

that's true - I've been told off in Manchester for not talking to strangers

malcolmsparks13:10:19

or at least, saying 'hello' , or 'howdo' or whatever you're meant to say in yorkshire (which i know manchester isn't in)

mccraigmccraig13:10:36

"smile love, it 'asn't 'appened yet"

malcolmsparks13:10:59

they need to invent an emoticon for that

malcolmsparks13:10:12

perhaps that's on the advanced course

mccraigmccraig13:10:55

too advanced for me

stijn14:10:46

how can I let a yada resource that returns a 404 continue in the bidi routes chain?

mccraigmccraig14:10:19

@malcolmsparks: i'm seeing some NPE (well, no protocol) coming out of representation/highest-charset-quality ...

mccraigmccraig14:10:26

stijn: have you tried having it return a nil response instead ?

stijn14:10:37

it doesn't return the default 404 handler, but some ex-info

stijn14:10:53

it looks like this

stijn14:10:56

(yada/yada (fn [ctx] (when-let [app (get apps (some-> ctx :parameters :app-id))]
                         (api/config-to-app
                           (get-in config [:statscentre :base-url])
                           (some-> ctx :parameters :version)
                           app)))
             {:error-handler identity
              :parameters    {:get {:path {:app-id Keyword}}}})

stijn14:10:36

so, if 'app-id' doesn't exist in the 'apps' map, I return nil

malcolmsparks14:10:59

@stijn the intention is that returning nil here would indeed yield 404.

malcolmsparks14:10:15

let me take a look

stijn14:10:56

@malcolmsparks: the response is 404

stijn14:10:42

but what I wanted was, instead of yada generating a 404 response, search for possible matches in the bidi routes, and finally hit the default not-found-handler (with the some-fn trick you use in modular/bidi)

stijn14:10:06

like bidi.ring/->ResourcesMaybe

malcolmsparks14:10:01

oh, that's impossible - because the bidi pattern has already matched and you've returned a handler - routing has ended

malcolmsparks14:10:49

instead, I suggest you write a Matched record, which does the same logic and returns nil if there's no app-id (presumably app-id is a path parameter)

malcolmsparks14:10:03

if there is an app-id, the Matched can 'succeed' and return {:handler this}, or {:handler foo} where foo is you Ring handler

stijn15:10:55

ok, sounds reasonable

stijn15:10:50

does bidi match in the order you define the routes?

malcolmsparks15:10:54

it's a bit confusing, but take a look at how ResourcesMaybe is implemented

malcolmsparks15:10:09

yes, as long as you provide them as a vector or vectors (pairs)

stijn15:10:27

it's like this: the REST API sits in "/", and every part of the path is a path parameter

malcolmsparks15:10:33

if order isn't important, you could use a map, but it's better if you use the vector of vectors style

stijn15:10:54

so I guess I need to put the API at the end in order to be able to match the resources

malcolmsparks15:10:00

yes, you'd have to be careful that the "/" route isn't matching greedily

stijn15:10:59

this yada/swaggered is soooo nice simple_smile

malcolmsparks15:10:07

I hope you get it working

malcolmsparks15:10:54

the yada.swagger/Swaggered resource makes quite a good example of what I was talking about earlier - it can match a bidi route and succeed based on some logic, and even serves itself, via the Ring protocol and using (succeed this ...)

malcolmsparks15:10:38

the yada swagger spec 'handlers' are themselves yada resources, it's all a bit incestuous down there

stijn15:10:43

@malcolmsparks: in order to add e.g. default representations to a set of yada resources I would yada.walk/merge-options ?

malcolmsparks15:10:05

yes, each yada resource is independent, shared nothing. That's quite an important principle, because I didn't want to complect resources with routing

malcolmsparks15:10:14

so the answer is data transformation

malcolmsparks15:10:34

you can post-process the API tree by walking it

stijn15:10:51

it feels good 😛

malcolmsparks15:10:54

and since yada resources are simply records, you can assoc/dissoc to them

malcolmsparks15:10:03

and they remain yada resources

stijn15:10:04

and it's a lot simpler to reason about then pedestal

malcolmsparks15:10:39

well, pedestal has a lot of strengths - it is more mature than yada but hopefully yada will mature too ove rtime

malcolmsparks15:10:36

bidi was heavily influenced by pedestal - but what I don't like about pedestal is the mixing of route declarations with inceptor chains - for me the domains are very different, one is a model, the other an implementation detail

stijn15:10:41

I didn't look too much into detail, but I found it hard to see where you put state in the interceptors

malcolmsparks16:10:17

@mccraigmccraig: Can you send me that stack-trace in the conneg?

malcolmsparks16:10:30

plus the resource that is causing it?