Lightweight REST server built with Windows 10 IOT Core in mind. Configuration created to resemble MVC and WebAPI attribute based configuration.
Create a new class that interits from ''Controller and implement REST-like paths using an attribute based system.
[RoutePrefix("test")]
public class TestController : Controller
{
[HttpGet]
[Route]
public HttpResponse Get()
{
return new HttpResponse(HttpStatusCode.Ok, "Testing");
}
[HttpGet]
[Route("method")]
public HttpResponse Method()
{
return new HttpResponse(HttpStatusCode.Ok, "<h1>Method</h1>");
}
[HttpGet]
[Route("withparam/{param1}")]
public HttpResponse WithParam(string param1)
{
return new HttpResponse(HttpStatusCode.Ok, $"got param1: {param1}");
}
[HttpPost]
[Route]
public HttpResponse Post([Body]string test)
{
return new HttpResponse(HttpStatusCode.Ok, $"Posted:{test}");
}
[HttpPost]
[Route("withbody")]
public HttpResponse JsonPost([JsonBody]string body)
{
return new JsonResponse(body);
}
[HttpGet]
[Route("jsonobject")]
public HttpResponse JsonObject()
{
return new JsonResponse(new { id = 1337, child = new { childprop1 = "testprop", childprop2 = new int[] { 1, 2, 3, 4 } } });
}
}
Create an instance of the server optionally specifying the port on which to run. Then add Controllers to the RestHandler. Finally start up the server ( preferably in an asynchronous task).
var httpServer = new HttpServer();
httpServer.RestHandler.RegisterController(new TestController());
ServerTask =
ThreadPool.RunAsync((w) =>
{
httpServer.StartServer();
});
No NuGet package available yet. For now just add the project to your solution and reference it in the projects you need.
This library is released under the MIT license. For more details see the LICENSE file.