Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 827
Willem-Aart Avatar asked Dec 01 '25 02:12

Willem-Aart


1 Answers

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.

like image 176
Laurence Avatar answered Dec 02 '25 15:12

Laurence



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!