Skip to content
Jark edited this page Feb 14, 2017 · 7 revisions

Purpose

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.

Let's go

  1. Create the project
  • Any "Universal Windows" project type will do
  1. Update Package.appxmanifest capabilities:
  • Internet (Client)
  • Internet (Client & Server)
  • Private Networks (Client & Server)
  1. Package installation
  • Use NuGet package manager and search for "Restup", make sure "Include prerelease" is checked
  1. Optionally, add a logger.

  2. 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!