14
Views
4
Comments
REST API Request parameter name validation

I am exposing a REST API and it's request body is like this:
{    

"size":10,   

"offset":0

}

size and offset are mandatory request parameters and their default value is set to 100 and 0.
Now, when I call my API with below request body it is still accepting the request and returning the result:

{    

"a":10,   

"b":0

}

It should give proper error message in such cases which is not happening right now, how can I check this?

2026-01-28 16-57-48
Mihai Melencu
Champion

Hello @Dhanashri Jaiswal ,

If you want to make size and offset truly mandatory and prevent invalid parameters, I think the best practice is to use query (URL) parameters instead of a request body.


2025-12-22 13-50-43
Sherif El-Habibi
Champion

Hello @Dhanashri Jaiswal,

If you want to strictly validate each input, as Mihai mentioned, you should send the request using URL parameters, like:

https://example.com/API/Post?a={x}&b={y}

That way, if x or y are missing, API will automatically return an error indicating a required field is missing.

2024-10-12 12-11-20
Kerollos Adel
Champion
Hallo @Dhanashri Jaiswal  , 


To avoid sending uncomplete data in the request , you can remove the default values and instead set them only after validating the values received in the request.


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.