简体   繁体   中英

REST API: Validating request params in GET request?

If you have query string param secondaryId on a GET endpoint of a REST API which searches a resource by that secondaryId , should you apply the same validation on that query string parameter that you would apply to the secondaryId in a CREATE or UPDATE?. For instance, if secondaryId can only be 10 characters long, should you validate the secondaryId in the querystring param of a GET request?

To me this seems out of place in the context of GETting a resource, but I can't find any resources online that mention this explicitly.

From the perspective of HTTP, if somebody tries to GET something using a url that doesn't point to anything, it simply means that that resource doesn't exist.

Irrespective of how the id is validated, or what you do with it... you probably just want to return 404 Not Found .

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