Input validation

Péter Szilágyi peterke at gmail.com
Sun May 9 05:13:10 EDT 2010


Hi, thanks for both of your responses. I managed to get it done using the
{halt, 422} (haven't figured out "halts" yet).

The thing with this validation is that I accept more than one input type
(XML, JSON, YAML... at least that's the plan :))) ), so I have a separate
processing function for each (which obviously just extracts the specific
data and passes it to a generic processing function). But because of this, I
cannot look at the data before teh processing function since I cannot decode
it. (Ok, I could work aroung the content_types_accepted method, but it
that's already there then there's no point in reimplementing the
functionality).

Thanks again a million,
  Peter

PS: I just played around with post, didn't get to do anything too serious,
so I didn't need validation there yet. But I do use POST as PUT into a
collection, so I'm if I'm not mistaking, I cannot use the process_post
function.

On Sun, May 9, 2010 at 9:45 AM, Daniel Reverri <reverri at gmail.com> wrote:

> There doesn't appear to be any functions currently implemented to return a
> 422 response code but you can return {halt, 422} from any function to end
> the processing of a request and return the 422 response code. An example
> return would be:
> {{halt, 422}, ReqData, State}
>
> The function malformed_request/2 will return a 400 response code if you
> return true:
> {true, ReqData, State}
>
>
>
> On May 8, 2010, at 7:45 PM, Michael McDaniel wrote:
>
> > On Sun, May 09, 2010 at 04:03:02AM +0300, Péter Szilágyi wrote:
> >>   Hi,
> >>     I have a small problem with POST/PUT methods. How can I validate the
> >>   input data and potentially throw an error message (422) if it fails? I
> >>   have the POST/PUT processing methods set in my content_types_accepted,
> >>   but those processing methods get called at the very end of the
> request,
> >>   and there are no more possibilities to bail out with an error (a
> >>   conflict error for example). The document isn't really clear on what
> >>   the result of these processing functions should be, but in my opinion
> >>   if I return false, then it should die with a validation failed error,
> >>   not return a 204.
> >>     Bottom line: I would like to implement input data validation and
> >>   corresponding error codes, how could I do this?
> >>   Thanks,
> >>     Peter
> > _______________________________________________
> >
> > (resending using original thread)
> >
> > Hi Peter.
> >
> > I validate POST data in my process_post/2 fun and then call
> > finish_request/2 with appropriate content (which may be an
> > error message, or may be the successful results of the POST).
> >
> > e.g. adjust RD passed to finish_request/2
> >
> > RD#wm_reqdata{resp_body="error message or successful results}
> >
> >
> > ~Michael
> >
> > --
> > Portland, Oregon, USA
> > http://trip.autosys.us
> >
> > _______________________________________________
> > webmachine mailing list
> > webmachine at lists.therestfulway.com
> >
> http://lists.therestfulway.com/mailman/listinfo/webmachine_lists.therestfulway.com
>
>
> _______________________________________________
> webmachine mailing list
> webmachine at lists.therestfulway.com
>
> http://lists.therestfulway.com/mailman/listinfo/webmachine_lists.therestfulway.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.therestfulway.com/pipermail/webmachine_lists.therestfulway.com/attachments/20100509/7b4416d8/attachment.html>


More information about the webmachine mailing list