Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 01, 2012 04:14 PM by benaw
Feb 28, 2012 04:21 PM|LINK
In a multi-tenant app, the request has an tenant identifier, the route is setup and value passed in the using the route to calls.
I would like the external api to follow a REST uri convention and aligned to their corresponding verb methods:
IQueryable<Dto.product> Get(string tenantId)
Dto.product Get(string tenantId, int id)
I can in part manage this if I have one get method but as soon as I have two I get, excuse pun, a few problems. Some rules would help or I can provide the results of a few tests I have done.
In my testing:
If id is not nullable, because it is required for this method, a HTTP status code of 400 - bad request is being returned, and error message "An optional parameter
must be a reference type, a nullable type, or be declared as an optional parameter.", when making a get request ../tenant/tenant-identifier/api/products.
If id is marked nullable because it is optional parameter on the route. I get a 404 - not found when making a request to ../tenant/tenant-identifier/api/products
Mar 01, 2012 04:14 PM|LINK
This is an interesting general question but my specific issue has been resolved and action routing now works for the two get methods.
Moral: don't inadvertently
use the mvc UrlParameter.Optional make sure you use RouteParameter.Optional. in System.Web.Http.