Program.cs 589 B

12345678910111213141516171819202122
  1. using System.Net.Http.Json;
  2. using Sisk.Core.Http;
  3. using Sisk.Core.Routing;
  4. var app = HttpServer.CreateBuilder ( host => {
  5. host.UseListeningPort ( "http://+:8080/" );
  6. } ).Build ();
  7. app.Router.SetRoute ( RouteMethod.Get, "/plaintext", PlainText );
  8. app.Router.SetRoute ( RouteMethod.Get, "/json", Json );
  9. app.Start ();
  10. static HttpResponse PlainText ( HttpRequest request ) {
  11. return new HttpResponse ( "Hello, world!" );
  12. }
  13. static HttpResponse Json ( HttpRequest request ) {
  14. return new HttpResponse ( JsonContent.Create ( new {
  15. message = "Hello, world!"
  16. } ) );
  17. }