What's the URL syntax for passing an object with a nested object to my ASP.NET Web API GET method? Is this possible?
http://mydomain/mycontroller?...
Mycontroller GET method:
public void Get([FromUri]MyType myType) { ... }
C# types:
public class MyType
{
public string Name { get; set; }
public NestedType Foo { get; set; }
}
public class NestedType
{
public int Bar { get; set; }
}
Best way to pass multiple complex object to webapi services is by using tuple other than dynamic, json string, custom class. No need to serialize and deserialize passing object while using tuple. If you want to send more than seven complex object create internal tuple object for last tuple argument.
By default, Web API extracts the value of the complex type from the request body, but here, we have applied the [FromUri] attribute. So now, Web API will extract the value of the Student properties from the query string instead of the request body.
In fact, there should be no more than 5 parameters in one request, otherwise, each of them will be difficult to control from the server and browser side. If you need to transfer a large amount of information, using the POST method is recommended.
It is possible -- try passing the URL in this format:
?myType.Foo.Bar=3&myType.Name=Maggie
If you're trying to implement a get that performs the following: 1) get by name 2) get by Foo.Bar
Then you could use querystring parameters. REST pass multiple inputs to GET method
If you are not really trying to do a GET and instead you are trying to POST data to the server, then you should use a POST.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With