REST: process_post flow included to content_types_accepted #396

Closed
wants to merge 1 commit into
from

Projects

None yet

3 participants

Contributor
egobrain commented Feb 1, 2013

Fix #356 issue.

Owner
essen commented Feb 1, 2013

My concern isn't so much the function itself, but more how to distinguish between PUT, POST to existing resource, POST to non-existing resource, and PATCH. Or whether we should. This should be clarified before code happens.

Contributor
bfrog commented Feb 15, 2013

Dictating what happens on POST to existing resources or non-existing resources shouldn't really be done in my opinion. Instead it should be user defined.

Perhaps the result from a POST callback handler determines what exactly happens.

content_types_accepted already allows you to potentially differentiate behaviour depending on verb or use the same behaviour for all POST/PUT/PATCH verbs.

Instead of having post_is_create -> true/false why not just let the return value of a POST callback determine what happens next?

Ex:

%% create with path 
post_json(Req, State) ->
    {Path, Req, State}

%% post failure
post_json(Req, STate) ->
   {false, Req, State}

%% post success without create
post_json(Req, State) ->
   {true, Req, State}

Right now I use POST sometimes just to implement a RPC like mechanism for things like OAUTH 2.0
which means I have to do

%% handle as RPC
post_json(Req, State) ->
     %% reply here...
     {halt, Req, State}

Which is kind of annoying.

In my opinion create_path, post_is_create, created_path, process_post should all just go away and instead the result of the content_types_accepted callback should vary the result instead. It simplifies the whole POST handling thing in my opinion.

Owner
essen commented Feb 16, 2013

Sounds good to me. Can't make it go through put_resource in cowboy_rest though, need a separate function to handle the differing return value we can get.

Owner
essen commented Apr 11, 2013

Done the change in 5a171d0. It's changing more than this PR, please look at it and give feedback. Thanks!

@essen essen closed this Apr 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment