Question: What is the best way to design a webservice that has optional parameters and different business logic for certain parameters?
Specific example:
The web service is intended to make it possible to search for houses.
A house resource has a structure like this:
{
"houseId": 3123,
"street": "Drake Street",
"houseNo": "789",
"city": "London",
"zipCode: "EC2R 6AB",
"country": "uk",
"coordinates": "51.506885, -0.128107",
"inventory": ["Veranda", "Baloncy", "Stove"]
}
The web service should perform a proximity search for a given address or coordinate and return houses that meet the given criteria.
Valid example:
/rest/v1/houses?city=London&street=Drake Street&inventory=Balcony&inventory=Veranda
Now it could also be possible to send requests as follows:
/rest/v1/houses?city=London&street=Drake Street&coordinates=51.506885, -0.128107
In this case, I would have to decide which geographical information has priority. Coordinates or Street+City+ZipCode.
In order to make things even more complicated, it should also be possible to pass the radius and the number of search results to the webservice. For performance reasons it should not be possible to get an unlimited number of search results if the country is missing.
Furthermore, it should not be possible to get an unlimited number of search results for an infinite radius. Therefore, one of the two values must be set to a finite number to trigger a search.
And so on... further logic...
Concluding:
It's not important to identify a particular house (resource) by id or anything like this. It is important to filter the existing houses by criteria.
When filtering, however, it must be ensured that there is different business logic for certain parameters.
How can I map such a problem elegantly in the backend? Are there any patterns that support such an approach?