Created
October 17, 2014 04:17
-
-
Save RhysC/722871e3e1858e3f7b40 to your computer and use it in GitHub Desktop.
Linqpad continues to be the coolest thing ever - WEBAPI in Linqpad with out all the drama. Logs all posts
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
| <Query Kind="Program"> | |
| <Reference><RuntimeDirectory>\System.Net.Http.dll</Reference> | |
| <NuGetReference>Microsoft.AspNet.WebApi.OwinSelfHost</NuGetReference> | |
| <Namespace>Microsoft.Owin.Hosting</Namespace> | |
| <Namespace>Owin</Namespace> | |
| <Namespace>System.Web.Http</Namespace> | |
| <Namespace>System.Net.Http</Namespace> | |
| <Namespace>System.Net</Namespace> | |
| </Query> | |
| void Main() | |
| { | |
| const string baseAddress = "http://localhost:9001/"; | |
| using (var server = WebApp.Start<Startup>(baseAddress)) | |
| { | |
| string.Format("Send a POST request to {0}api/Test to get started", baseAddress).Dump(); | |
| Console.ReadLine(); | |
| } | |
| } | |
| public class Startup | |
| { | |
| public void Configuration(IAppBuilder appBuilder) | |
| { | |
| var config = new HttpConfiguration(); | |
| config.Routes.MapHttpRoute("DefaultApi","api/{controller}/{id}",new { id = RouteParameter.Optional }); | |
| appBuilder.UseWebApi(config); | |
| } | |
| } | |
| public class TestController : ApiController | |
| { | |
| public HttpResponseMessage Post() | |
| { | |
| var route = Request.GetRouteData().Route.RouteTemplate; | |
| var method = Request.Method.Method; | |
| var url = Request.RequestUri.AbsoluteUri; | |
| new { | |
| Route = Request.GetRouteData().Route.RouteTemplate, | |
| RequestMethod =Request.Method.Method, | |
| RequestUri = Request.RequestUri.AbsoluteUri, | |
| Headers = Request.Headers, | |
| Content = Request.Content.ReadAsStringAsync().Result | |
| }.Dump(); | |
| return new HttpResponseMessage(HttpStatusCode.OK); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment