using ln.http.api.attributes; using ln.http.router; using ln.type; namespace ln.http.api.demo { class Program { static void Main(string[] args) { DemoApi demoApi = new DemoApi(); SimpleRouter webRouter = new SimpleRouter(); webRouter.AddSimpleRoute("/api/v1/*", demoApi); HTTPServer httpServer = new HTTPServer(new LoggingRouter(webRouter)); httpServer.AddEndpoint(new Endpoint(IPv6.ANY, 3434)); httpServer.Start(); } } class DemoApi : WebApiController { [POST("/helloworld/:n")] [POST("/helloworld")] public string GetHelloWorld([FromContent( SourceName = "m")]int n, [FromParameter( SourceName = "n")]int i = -1) { return string.Format("Hello World. You gave me a n={0} / i={1}!", n, i); } [GET("/users/:id")] public User GetUser(int id) { return new User(); } [POST("/users")] public User CreateUser([FromContent]User user) { user.PrimaryGroup += " / or another one"; return user; } [GET("/users")] public User[] GetUsers() { return new User[]{ new User() { Username = "User A" }, new User() { Username = "User B" }, new User() { Username = "User C" } }; } [GET("/header/:headername")] public string GetHeaderValue(HttpRequest request, string headername) { return request.GetRequestHeader(headername); } } class User { public string Username { get; set;} = "niclasundharald"; public string PrimaryGroup { get; set; } = "admins"; } }