[erlang-questions] Webmachine content_types_accepted w/ POST

Loïc Hoguin <>
Tue Mar 8 13:09:30 CET 2016


On 03/08/2016 12:07 PM, Torben Hoffmann wrote:
> Hi,
>
> I have a URI where I accept a POST.
>
> It has to support one or multiple entities for creation as JSON in the
> body.
> So post_is_create/2 should return false.
> Hence I have to implement process_post/2 to deal with the POST.
> So far, so good.
>
> But I have to write
>
> content_types_accepted(RD, Ctx) ->
>      {[{"application/json", bogus_handler_name}], RD, Ctx}.
>
> for the JSON body to be accepted.

Cowboy REST has the same behavior. I recommend putting undefined 
personally. I suppose '' would also work.

It might be worth having a special return value known to 
Webmachine/Cowboy that would never get dispatched, in case the developer 
leaves GET enabled.

> I can write whatever as the handler function, because it will not be
> called by Webmachine.
>
> I only allow JSON on that POST, so I can control it and return an empty
> list of accepted types for other URI/method combos.
>
> It seems a little dirty to me.
> I can live with it, just wanted to hear what others do.
>
> Cheers,
> Torben
>

-- 
Loïc Hoguin
http://ninenines.eu
Author of The Erlanger Playbook,
A book about software development using Erlang


More information about the erlang-questions mailing list