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:
1)
../tenant/tenant-identifier/api/products
IQueryable<Dto.product> Get(string tenantId)
2)
../tenant/tenant-identifier/api/products/5
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
benaw
Member
211 Points
95 Posts
What are the request to overloaded method rules for GET? bug?
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:
1)
../tenant/tenant-identifier/api/products
IQueryable<Dto.product> Get(string tenantId)
2)
../tenant/tenant-identifier/api/products/5
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
benaw
Member
211 Points
95 Posts
Re: What are the request to overloaded method rules for GET? bug?
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.