[99s-extend] Using cowboy_req:body more than once per request

Loïc Hoguin essen at ninenines.eu
Tue Sep 16 00:42:20 CEST 2014


On 09/16/2014 12:35 AM, Paulo F. Oliveira wrote:
> Hi.
>
>> It seems a bit weird to me to read the body and validate it before validating the request itself.
>
> It certainly seems like it, but I had no immediate solution and
> instead of changing a dozen handlers, this seemed faster to implement
> :D. I don't understand what you mean by "validating the request
> itself". I read the header (I mentioned previously) and the body and
> check one against the other. They are present and enough for the
> _validator_ to make a decision, but I might be missing something here.

Like, is it the right method? Are the bindings/qs parameters/headers 
present and valid? And so on. The body should be the last thing you 
check, due to how expensive it can be, not the first.

>> I would explicitly put these checks in the handler directly. This of course means that there is no need to read it twice anymore.
>
> I've been trying to find a way to easily share code between handlers
> without having to rewrite a lot of code (even if I do decide to put
> things in a library function - or several). I recently came across
> https://github.com/opscode/mixer. Have you ever used it?

I usually share code by writing functions. Then I call these functions 
where needed.

-- 
Loïc Hoguin
http://ninenines.eu


More information about the Extend mailing list