0

For reasons I won't get into here, we have 2 .NET Web APIs (A and B). A website sends JSON to A via jQuery's .ajax(), and then A needs to pass it on to B.

In A, I have a model as a parameter in the controller which gets mapped from the json. So:

Person: { 
  Surname: "Me",
  FirstName: "Hello" 
}

arrives at my controller method as:

submitInfo(Person thePerson)

How do I make a call from A to B using this model? Do I need to serialize it to json again and then send it to B to get re-mapped? How do I do that?

I read this article about how to call a REST api from .NET using query string parameters in the url, but I'm not sure how that works with my model or even when it's serialized to json...

My API controller methods are the same (since it's effectively the same functionality):

public IHttpActionResult submitInfo(Person thePerson)
{

}
Community
  • 1
  • 1
Daniel Minnaar
  • 5,865
  • 5
  • 31
  • 52

1 Answers1

0

You need to use parameterbinding

Your request url should be appended with string.Format("?Surname={0}&FirstName={1}", Person.Surname, Person.FirstName) And on the api action u should use FromUri attribute

so your api knows that thePerson object will be coming from uri parameter i.e.

public IHttpActionResult submitInfo([FromUri]Person thePerson){ }

madan
  • 445
  • 6
  • 16