Thursday, March 20, 2014

POSTing Multiple Parameters with Web API

So you've decided to use Web API to build some RESTful services (or at least some RESTful methods) for your application and you now realize that when you POST to those services you have a need to send two parameters.  For the sake of argument, let's say you want to send first name and last name to a method called SaveName, like this:

   1:  [HttpPost]
   2:  public HttpResponseMessage SaveName(string firstName, string lastName)
   3:  {
   4:              
   5:  }

Yeah, good luck with that.  See, right out of the box Web API doesn't allow this.  I don't remember what happens, but it doesn't work the way you think it will.  Rick Strahl wrote a really in-depth and quite good post about this some time ago and since I can't possibly say it any better than him, I'm going to direct you there.

While you're there you should also check out these two other posts about the exact same topic.  Seriously, that guy knows what he's talking about.

No comments:

Post a Comment