-
Notifications
You must be signed in to change notification settings - Fork 48
One pager
Jark edited this page Feb 14, 2017
·
7 revisions
About 90% of the people reading the wiki will only look the most basic sample, they'll figure out the details by themselves. To prevent you from clicking through the whole wiki to find the only mandatory steps to get things going we introduced this page. If your read this, you will have a webserver running in a couple of minutes.
- Create the project
- Any "Universal Windows" project type will do
- Update Package.appxmanifest capabilities:
- Internet (Client)
- Internet (Client & Server)
- Private Networks (Client & Server)
- Package installation
- Use NuGet package manager and search for "Restup", make sure "Include prerelease" is checked
-
Optionally, add a logger.
-
Add code to run server
public class Main
{
public async Task Run()
{
var restRouteHandler = new RestRouteHandler();
restRouteHandler.RegisterController<ParameterController>();
var configuration = new HttpServerConfiguration()
.ListenOnPort(8800)
.RegisterRoute("api", restRouteHandler)
.EnableCors();
var httpServer = new HttpServer(configuration);
await httpServer.StartServerAsync();
// now make sure the app won't stop after this (eg use a BackgroundTaskDeferral)
}
}
public class DataReceived
{
public int ID { get; set; }
public string PropName { get; set; }
}
[RestController(InstanceCreationType.Singleton)]
public class ParameterController
{
[UriFormat("/simpleparameter/{id}/property/{propName}")]
public IGetResponse GetWithSimpleParameters(int id, string propName)
{
return new GetResponse(
GetResponse.ResponseStatus.OK,
new DataReceived() { ID = id, PropName = propName });
}
}
And that's it, happy coding!