ssuhat
ssuhat

Reputation: 7656

REST API validation for query string

I'm designing a REST API using Laravel 5.1.

I'm curious is it necessary to validate query string?

https://www.example.com/users?page=1;count=20

what if user put page="abc" or count="abc"?. Should i return an error or just return empty result?

Thanks

Upvotes: 1

Views: 529

Answers (1)

Pedro Werneck
Pedro Werneck

Reputation: 41878

In theory an URI is an atomic identifier, so you should return a 404 Not Found, regardless of the wrong syntax or semantics. In practice, it's better to return a 400 Bad Request and a detailed explanation of the error.

Upvotes: 1

Related Questions