Skip to content

Instantly share code, notes, and snippets.

@darsen
Created March 25, 2016 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darsen/0601e9148e05b206858b to your computer and use it in GitHub Desktop.
Save darsen/0601e9148e05b206858b to your computer and use it in GitHub Desktop.
Send complex objects to .Net Web Api through URL using FromUri attribute
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