Is there a way in webapi(besides odata) to specify multiple queries? Here is the scenario: A custom sproc. that accepts 2 zip codes, performs distance calculation and return the distance The WebAPI endpoint accepts the zips and calls into the sproc. and returns a Distance DTO class ZIPDistance { public string Zip1, public string Zip2, public sttring Distance }
The URL for this: "/api/ZipDistances?$select=Distance&$filter=Zip1 eq 13240 and Zip2 eq 90210 In the ZipDistancesController we extract the parameters from the above query using ODataQueryOptions, call into the sproc. and return the DTO above.
For potential performance reasons it was requested that the above endpoint somehow accept a collection of zip code pairs i.e. a collection of the "ZIPDistance" DTOs representing the "pairs" of zips for which we need to call into the sproc above, loop over the DTOs, invoke the sproc. per DTO and return a collection of DTOs for the result so that a client would make a single HTTP call instead of multiple calls and obtain all results in 1 call.
The only way that I am aware of doing is via a POST and pass in the collection of ZIPDistances representing the zip code pairs in the payload, but this is fundamentally against REST since now we change the semantic meaning of POST to mean data retrieval (i.e. GET)
The question is whether the above scenario supported by WEBAPI and what would be the best way for implementing the above without overloading verb meaning and causing confusion.
UPDATE:
I've prototyped out one possible solution here which involves embedding the pairs in the URL:
http://<host>/api/ZipDistances?$select=Distance&$filter=Pairs eq 'Zip1 eq 13240 and Zip2 eq 90210,Zip1 eq 13241 and Zip2 eq 90211'
and the corresponding DTO:
public class ZipDistanceDTO
{
public string ZipPairs { get; set; }
public string Distance { get; set; }
}
This would return the following result:
[{"ZipPairs":"'Zip1 eq 13240 and Zip2 eq 90210","Distance":"558"},
{"ZipPairs":"Zip1 eq 13241 and Zip2 eq 90211'","Distance":"558"}]
Comments/Thoughts on this would be appreciated.
UPDATE (2): I've posted another prototype here that uses a Query resource