In my system, I have multiple services exposing REST apis for their resources. A specific service on the system needs to make rest calls to other services in dry-run mode in specific circumstances just to do validation. Even though the body of the request has meaningful payload for the api, nothing will be persisted, no states will be changed and no messages will be sent. The tricky part is that if this service calls a REST api which didn't implement dry-run mode, it will modify the resource instead of just validating. I need a way to make dry-run requests only if the receiving service implemented dry-run in its api, otherwise the request must fail.
I had these ideas so far:
Passing a query parameter
I could pass a flag as a query parameter but the request still goes through if the api doesn't know of the parameter.
POST /resource?dry-run=true
Passing a flag in header
Similar to query parameter, unknown header fields are ignored.
Exposing a dry-run api just for validating
This solution works as I can verify dry-run version of the URL exists or not but I don't want to expose more endpoints just for validation
POST /resource
POST /resource/dry-run
PUT /resource/{id}
PUT /resource/{id}/dry-run
Inject the flag to the body of resource
This looks to be a solution but when the api doesn't support this field, JSON serialization will fail. In that case, I can't tell whether it is because dry-run is not supported by the api or there is actually a problem in the body. Also, it doesn't feel right since dry-run is not a part of the resource.
POST /resource
{
"dry-run":true,
...
...
}
Is there a better way to implement a dry-run feature to REST api where the request will fail if the service have not implemented it?