Skip to content

Instantly share code, notes, and snippets.

@hudo
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save hudo/97f0df43b4e719413709 to your computer and use it in GitHub Desktop.

Select an option

Save hudo/97f0df43b4e719413709 to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
var server = WebApp.Start("http://+:56789", builder =>
{
var configuration = new HttpConfiguration();
configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
configuration.Routes.MapHttpRoute("default", "api/{controller}");
configuration.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = TypeNameHandling.Auto;
configuration.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
builder.UseWebApi(configuration);
});
var httpClient = new HttpClient();
var payload = httpClient.GetStringAsync("http://localhost:56789/api/test").Result;
var sampleResponse = JsonConvert.DeserializeObject<SampleResponse>(payload, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
server.Dispose();
Console.WriteLine("done.");
}
}
public class TestController : ApiController
{
public SampleResponse Get()
{
return new SampleResponse { Name = "Banana", Vehicle = new Car { Brand = "Rimac" }};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment