Last active
August 29, 2015 14:18
-
-
Save hudo/97f0df43b4e719413709 to your computer and use it in GitHub Desktop.
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
| 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