简体   繁体   中英

Laravel 5 REST API validation

I'm quite new to both RESTful API's and Laravel 5, so excuse me for any dumb questions. :-)

What's the best way to validate API requests (POST/PUT) in Laravel 5? 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? Is there a better alternative?

Also, how would one go about validating query strings in GET requests? 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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