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?
Hi @Dhanashri Jaiswal ,
Please check the below post:
https://success.outsystems.com/documentation/11/integration_with_external_systems/rest/expose_rest_apis/add_custom_authentication_to_an_exposed_rest_api/
Regards,
Manish Jawla
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.
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.
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.