简体   繁体   English

Laravel 5 REST API验证

[英]Laravel 5 REST API validation

I'm quite new to both RESTful API's and Laravel 5, so excuse me for any dumb questions. 我对RESTful API和Laravel 5都很陌生,所以请原谅任何愚蠢的问题。 :-) :-)

What's the best way to validate API requests (POST/PUT) in Laravel 5? 在Laravel 5中验证API请求(POST / PUT)的最佳方法是什么? I've learned about Form Request Validation , but that seems targeted towards forms. 我已经了解了表单请求验证 ,但这似乎是针对表单的。 Would it make any sense to use this for a HTTP REST API as well? 将它用于HTTP REST API也没有任何意义吗? Is there a better alternative? 还有更好的选择吗?

Also, how would one go about validating query strings in GET requests? 另外,如何在GET请求中验证查询字符串? Is that something to handle in the controller itself? 这是控制器本身要处理的吗?

The best option is to use the Form Request Validation. 最好的选择是使用表单请求验证。 The word "form" in the title is misleading - as it is really the ability to handle validation on any request - regardless of the source. 标题中的“形式”一词具有误导性 - 因为它确实能够处理任何请求的验证 - 无论来源如何。

You can handle GET requests inside the Request validator - so that all your validation is in one single location. 您可以在请求验证程序中处理GET请求 - 以便您的所有验证都在一个位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM