Fork me on GitHub
#yada
<
2016-02-04
>
lsnape10:02:25

Hello, is there an easy way to make a yada resource allow all methods? That is without having to specify them individually.

lsnape10:02:06

I’m thinking specifically about 404s

imre10:02:33

you mean to provide a resource that always return a 404 no matter the method?

lsnape10:02:37

yes precisely

malcolmsparks10:02:05

@lsnape: not yet, i'm considering it

malcolmsparks10:02:32

because of the 404 case, actually

lsnape10:02:28

I can’t think where else I might want that behaviour

imre10:02:26

will (resource nil) not give you that functionality?

lsnape10:02:40

but 404s are baked into our project templates and writing it was a bit verbose!

imre10:02:00

(yada.protocols/as-resource nil)

imre10:02:34

hmm no looks like that only does the get part

lsnape10:02:10

really? Actually it seems to work for me: for PUT, POST, DELETE

imre10:02:53

I just looked at the returned resource model tbh but it might actually work

lsnape11:02:58

It’s not obvious how one would override the response, however. It’s fine for my purposes now though simple_smile

lsnape11:02:40

(as in, customise the body, error message etc.)

imre11:02:22

I guess you could re-implement the as-resource function for nil in your project?

lsnape11:02:24

ah yes that would work. cheers

malcolmsparks16:02:13

I think sending a POST request to (yada nil) will return a 405 rather than a 404, which I didn't expect

malcolmsparks16:02:34

"The 404 (Not Found) status code indicates that the origin server did not find a current representation for the target resource" from RFC 7231

malcolmsparks16:02:25

So 404 could mean 'you can post/put to me, but I don't currently have a representation' OR there is no resource here

malcolmsparks16:02:34

It's quite tricky, but I think the right thing to do for (yada nil) is ALWAYS return 404. That's what most people (including me) would expect. It's also useful as a way of terminating a bidi routing tree as a 'catch-all' - [true (yada nil)] feels short and easy to remember

malcolmsparks16:02:22

So for this reason I'm thinking to say that a resource must either have :methods or :response (which would be a function)

malcolmsparks16:02:53

This also has another benefit of bringing back the (yada (fn [ctx] ...)) case

malcolmsparks16:02:27

there are some cases where you just want to take an existing Ring handler and adapt it to yada

lsnape16:02:20

making a POST request to an unknown resource with handler (yada nil) responds with a status 404 for me. That’s using [yada "1.1.0-20160202.093502-16”]

lsnape16:02:20

which I’m comfortable with too. A 405 response I would find surprising

dominicm16:02:36

What is the origin of the yada name @malcolmsparks?

malcolmsparks16:02:03

it's a hat-tip to zach and aleph, it means 'to know' - the opposite of a Ring handler function that is 'only callable'

malcolmsparks16:02:19

a yada resource-model gives you information up-front

malcolmsparks16:02:44

to be fair, we tend to use 4-letter words in juxt because they're short and quick to type (we're busy people!)

dominicm16:02:10

juxt yada bidi aero, those are the ones I can name off the top of my head. Didn't expect it would have a meaning like that.

dominicm16:02:12

Hebrew, yada is the pa'al construction, of the hebrew, interesting.

lockdown17:02:14

is yada meant to be used with bidi?

dominicm17:02:29

They go well together, but not forced.

malcolmsparks17:02:52

@dominicm: good summary