Skip to content

Instantly share code, notes, and snippets.

@scottoffen
Last active July 28, 2017 15:05
Show Gist options
  • Save scottoffen/b26a928c8c962188230307ac1c1b3df0 to your computer and use it in GitHub Desktop.
Save scottoffen/b26a928c8c962188230307ac1c1b3df0 to your computer and use it in GitHub Desktop.
Grapevine: Input validation
// the context will be passed into the method automatically by the router
server.Router.BeforeRouting += context =>
{
// Do your input validation here
if (!context.Request.Payload.Contains("elephant"))
{
// by sending a response to the request, no additional processing will occur.
context.Response.SendResponse(HttpStatusCode.BadRequest, "no elephants allowed");
}
/*
* No need to do anything else.
* Once all before handlers have executed, the
* routes will be executed, unless one of the event
* handlers have already sent a response.
*/
};
server.Router.BeforeRouting += context =>
{
/*
* You can have multiples of these, too, if you
* are initializing multiple autonomous things.
*/
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment