Use cases for can-post-to-missing? and its default

22 views
Skip to first unread message

Christopher Adams

unread,
Oct 4, 2016, 1:16:02 AM10/4/16
to clojure-...@googlegroups.com
I'm curious about the common use cases for "can-post-to-missing?" and
the rationale for having it default to true.

I'm asking because, Webmachine (where the callback is
allow_missing_post) defaults to false. I'm wondering why Liberator made
a different decision here, and whether the use cases for this behavior
are more common than I realized.

I can think of a very common scenario where "can-post-to-missing?"
should be false: when the resource is on a route like /users/:id, and
"exists?" does a database lookup, and should return 404 for all methods
if there's no record.

In contrast, scenarios where can-post-to-missing? should be false strike
me as much less common:

* allowing POST to behave like PUT (in the above scenario)
* having a resource like /sessions that is 404 for GET but can POST to
create a new resource
* writing a single resource that handles routes for POST /users and
GET/PUT /users/:id

To me it seems like, if I have to implement "exists?" for my resource, I
would expect it to return 404 by default when that function is false.
Then, if I thought of an edge case ("Well, but now I want it to handle
POST if it's missing..."), at that point I can implement
"can-post-to-missing?".

What am I overlooking that tipped the balance in favor of making
"can-post-to-missing?" default to true?

Thanks in advance for any insights you might have.

Christopher

chris...@fabricatorz.com

unread,
Oct 4, 2016, 1:18:51 AM10/4/16
to Liberator


On Tuesday, October 4, 2016 at 1:16:02 PM UTC+8, Christopher Adams wrote:
In contrast, scenarios where can-post-to-missing? should be false

I meant to write here "scenarios where can-post-to-missing? should be TRUE"

Philipp Meier

unread,
Oct 4, 2016, 3:50:15 AM10/4/16
to Liberator
Hi Christopher,


Am Dienstag, 4. Oktober 2016 07:16:02 UTC+2 schrieb Christopher Adams:
I'm curious about the common use cases for "can-post-to-missing?" and
the rationale for having it default to true.

I'm asking because, Webmachine (where the callback is
allow_missing_post) defaults to false. I'm wondering why Liberator made
a different decision here, and whether the use cases for this behavior
are more common than I realized.

I don't remember why liberator is deviating from webmachine in this case. It's quite possible I wasn't looking at the defaults of webmachine at all and all the matches are coincidental.
 

I can think of a very common scenario where "can-post-to-missing?"
should be false: when the resource is on a route like /users/:id, and
"exists?" does a database lookup, and should return 404 for all methods
if there's no record.

In contrast, scenarios where can-post-to-missing? should be false strike
me as much less common:

[...]
 

To me it seems like, if I have to implement "exists?" for my resource, I
would expect it to return 404 by default when that function is false.
Then, if I thought of an edge case ("Well, but now I want it to handle
POST if it's missing..."), at that point I can implement
"can-post-to-missing?".

Well, simply declare :can-post-to-missing? false in your resources, then. No big deal, I guess. 

What am I overlooking that tipped the balance in favor of making
"can-post-to-missing?" default to true?

No, there's no secret reason, don't overthink this.
 

Thanks in advance for any insights you might have.

I've got only one: api design is hard :-) Maybe you enjoy my talk at the 2015 conj https://www.youtube.com/watch?v=fTBEMpmFFmw 

-billy.

Christopher Adams

unread,
Oct 4, 2016, 7:42:24 AM10/4/16
to clojure-...@googlegroups.com


On 10/04/2016 03:50 PM, Philipp Meier wrote:
> Am Dienstag, 4. Oktober 2016 07:16:02 UTC+2 schrieb Christopher Adams:
>
> I'm curious about the common use cases for "can-post-to-missing?" and
> the rationale for having it default to true.
>
> I'm asking because, Webmachine (where the callback is
> allow_missing_post) defaults to false. I'm wondering why Liberator made
> a different decision here, and whether the use cases for this behavior
> are more common than I realized.
>
>
> I don't remember why liberator is deviating from webmachine in this
> case. It's quite possible I wasn't looking at the defaults of webmachine
> at all and all the matches are coincidental.

Thanks for your response Philipp. Your answer satisfies my curiosity.
Since Liberator has added quite a few features over Webmachine, I
wondered if the "can-post-to-missing?" default was anything more than an
incidental change.

I'd be curious to hear if anyone on this list uses this feature, and
how, or alternatively if you often just set it to false.

Christopher
Reply all
Reply to author
Forward
0 new messages