I am trying to map strongly typed objects to input parameters to ApiController methods like WebApi Preview 6 OperationHandler's allowed me to do.
Lets say I have a structured way to query some of my resource endpoints. Lets say that I have a strongly typed object that I want to use to represent that query. How can you pump that input parameter into an ApiController method? Furthermore, how can
you pass in multiple strongly typed objects into that same ApiController method?
Example: Assume Query, Paging, and Properties are objects I have created that I want to pump into this method as I would with an OperationHandler in WebApi Preview 6.
public class ResourceAController : ApiController {
public List<ResourceA> GetAll(Query query, Paging paging, Properties properties){
......
}
}
1) Is there a way to do this without having the endpoint blow up when you hit it? Right now mine complains about not being able to bind the content for multiple objects.
2) What is the cleanest way to do this.
Are the parameter values being supplied by the caller, or do you want to create them on the server and inject them in? You might want to consider a custom model binder, and perhaps use parameter binding rules to configure them.
I am trying to evaluate the request (the query string) and create a strongly typed object to pass into the input parameter. Additionally I would like the mechanism to be something that I can drive as an Architect and have my developer use this functionality
when creating new services without having to know exactly how to do some particulars.
I'll take a look at the links and letcha know what if that solves the issue.
Thanks for that post, unfortunately I am not trying to do exactly this.
I am very familiar with REST architecture and do not want to turn it into an RPC request/response. I want to take my query string, parse it and process it into strongly typed objects, and provide those objects to the method being called. For the time being
(to make it easier) I am simply creating my own base class and stuffing that parsing logic and property there. However, I would really like to leverage the pipeline and pass it in the input parameters for the method.
MyObject A = BuildObjectFromQuerystring(uri);
MyObject2 B = BuildObject2FromQuerystring(uri);
MyObject3 C = BuildObject3FromQuerystring(uri);
I would like to do this parsing before the method gets called. and I would like my method to look like this:
public SomeResourceObject Get(string id, MyObject a, MyObject2 b, MyObject3 c){
Dot_Net_Guy
None
0 Points
8 Posts
Mapping Input Parameters to ApiController methods
Dec 07, 2012 03:51 PM|LINK
I am trying to map strongly typed objects to input parameters to ApiController methods like WebApi Preview 6 OperationHandler's allowed me to do.
Lets say I have a structured way to query some of my resource endpoints. Lets say that I have a strongly typed object that I want to use to represent that query. How can you pump that input parameter into an ApiController method? Furthermore, how can you pass in multiple strongly typed objects into that same ApiController method?
Example:
Assume Query, Paging, and Properties are objects I have created that I want to pump into this method as I would with an OperationHandler in WebApi Preview 6.
public class ResourceAController : ApiController {
public List<ResourceA> GetAll(Query query, Paging paging, Properties properties){
......
}
}
1) Is there a way to do this without having the endpoint blow up when you hit it? Right now mine complains about not being able to bind the content for multiple objects.
2) What is the cleanest way to do this.
Thanks in advance
Dot_Net_Guy
None
0 Points
8 Posts
Re: Mapping Input Parameters to ApiController methods
Dec 10, 2012 01:16 PM|LINK
bump.
While you ponder this take a look at a project I have out there to answer these issues: http://SimpleRest.Codeplex.com
priya_marwah...
Member
81 Points
52 Posts
Re: Mapping Input Parameters to ApiController methods
Dec 11, 2012 10:02 AM|LINK
Are the parameter values being supplied by the caller, or do you want to create them on the server and inject them in? You might want to consider a custom model binder, and perhaps use parameter binding rules to configure them.
These links might help:
http://blogs.msdn.com/b/jmstall/archive/2012/05/11/webapi-parameter-binding-under-the-hood.aspx
http://ofps.oreilly.com/titles/9781449337711/ch_formatters_and_model_binding.html
Dot_Net_Guy
None
0 Points
8 Posts
Re: Mapping Input Parameters to ApiController methods
Dec 11, 2012 10:52 PM|LINK
bump.
While you ponder this take a look at a project I have out there to answer these issues: http://SimpleRest.Codeplex.com
Dot_Net_Guy
None
0 Points
8 Posts
Re: Mapping Input Parameters to ApiController methods
Dec 11, 2012 10:56 PM|LINK
I am trying to evaluate the request (the query string) and create a strongly typed object to pass into the input parameter. Additionally I would like the mechanism to be something that I can drive as an Architect and have my developer use this functionality when creating new services without having to know exactly how to do some particulars.
I'll take a look at the links and letcha know what if that solves the issue.
Ankit Purani...
Member
334 Points
65 Posts
Re: Mapping Input Parameters to ApiController methods
Dec 13, 2012 07:57 AM|LINK
Take a look at this post:
http://www.west-wind.com/weblog/posts/2012/May/08/Passing-multiple-POST-parameters-to-Web-API-Controller-Methods
This may help you get an idea.
Ankit
My .NET Blog
(Please Mark As Answer, if this helps you)
Dot_Net_Guy
None
0 Points
8 Posts
Re: Mapping Input Parameters to ApiController methods
Dec 13, 2012 01:12 PM|LINK
Thanks for that post, unfortunately I am not trying to do exactly this.
I am very familiar with REST architecture and do not want to turn it into an RPC request/response. I want to take my query string, parse it and process it into strongly typed objects, and provide those objects to the method being called. For the time being (to make it easier) I am simply creating my own base class and stuffing that parsing logic and property there. However, I would really like to leverage the pipeline and pass it in the input parameters for the method.
MyObject A = BuildObjectFromQuerystring(uri);
MyObject2 B = BuildObject2FromQuerystring(uri);
MyObject3 C = BuildObject3FromQuerystring(uri);
I would like to do this parsing before the method gets called. and I would like my method to look like this:
public SomeResourceObject Get(string id, MyObject a, MyObject2 b, MyObject3 c){
}
Thanks again for the posts thus far.