I'm trying to understand how Web-Api Resolves Routes. I have two routes which use the same base path
[WriteRoute(DivisionAPIRoutes.PAYROLL_IMPORT_PTO)]
[HttpPost]
public void ImportPTOByIds(GlobalEntityKey<IDivision> parentId, GlobalEntityKey<IDivisionPayCalendar> id,
ImportPTORequestDTO importPTORequest, [FromUri] GlobalEntityKey<IPTORequest>[] ptoRequestIds)
{
GlobalFactory<IEmployeePTOListService>.Instance.ImportPTOByIds(parentId, id, ptoRequestIds, importPTORequest);
}
[WriteRoute(DivisionAPIRoutes.PAYROLL_IMPORT_PTO)]
[HttpPost]
public void ImportPTOByFilter(GlobalEntityKey<IDivision> parentId, GlobalEntityKey<IDivisionPayCalendar> id, ImportPTORequestDTO importPTORequest, string filterOptions,
[FromUri] GlobalEntityKey<IPTORequest>[] excludedPTORequestIds)
{
var filterOptionsDTO = JsonConvert.DeserializeObject<FilterOptionsDTO>(filterOptions);
GlobalFactory<IEmployeePTOListService>.Instance.ImportPTOByFilter(parentId, id, filterOptionsDTO, excludedPTORequestIds, importPTORequest);
}
NOTE: By default, builting CLR types string, int are retrieved from the URI
I'm making a post request which work fine but I'm trying to understand the underlying logic for how the route resolves to the method:
(Decoded for Convenience)
https://localhost/api/paystream/v1/divisions/1af4edea-d442-4fda-b29d-02c42951c0d0/payrolls/cd2ed43d-0f3d-48fb-8d00-15294a8fa06e/_actions/import-pto?filterOptions={"query":"","filterParameters":[{"fieldName":"RequestStartDate","parsebleValue":"2016-01-01","filterType":"GreaterThanOrEqual"},{"fieldName":"RequestStartDate","parsebleValue":"2017-12-31","filterType":"LessThanOrEqual"}]}
PostBody: { AlwaysCreateNewCheck: false, PayBatchType: 'Checks', PayBatchId: '1903771' }
If I Omit the excludedPTORequestIds from the request. This will still resolve to ImportPTOByFilter
but if I include the excludedPTORequestIds and Omit the filterOptions
the ImportPTOByIds
is Selected.
I'm inclined to think that Lists, and Array which are handled by the model binder have different behaviors than other Default CLR Types which model bind (string, int, Guid, etc).
While string are required and will throw a 404 or resolve to other routes, Array's are not required to be explicitly defined in the request.
Is it safe to assume that, What are the other rules for route resolution from WebApi.