Created
March 25, 2016 16:17
-
-
Save darsen/0601e9148e05b206858b to your computer and use it in GitHub Desktop.
Send complex objects to .Net Web Api through URL using FromUri attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace FromUri.Controllers | |
{ | |
using System; | |
using System.Web.Http; | |
/// <summary> | |
/// Url sample call: | |
/// http://localhost:50872/api/test?key.org=abc&key.dest=123&key.when=2010-01-01T00:00:00&foo=1&bar=bbbrr&foobar.foo=2&foobar.bar=xyz | |
/// </summary> | |
public class TestController : ApiController | |
{ | |
public string Get([FromUri] Key key, int foo, string bar, [FromUri] FooBar fooBar) | |
{ | |
return "key org:" + key.Org + " Key when" + key.When + " foo: " + foo + " bar: " + bar + " fooBar.Foo " + | |
fooBar.Foo + " fooBar.Bar " + fooBar.Bar; | |
} | |
} | |
public class Key | |
{ | |
public string Org { get; set; } | |
public string Dest { get; set; } | |
public DateTime When { get; set; } | |
} | |
public class FooBar | |
{ | |
public int Foo { get; set; } | |
public string Bar { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment