Program.cs 871 B

1234567891011121314151617181920212223242526272829303132
  1. using System.Net;
  2. using System.Text.Json;
  3. using Wired.IO.App;
  4. using Wired.IO.Http11.Response.Content;
  5. using Wired.IO.Protocol.Response;
  6. using StringContent = Wired.IO.Http11.Response.Content.StringContent;
  7. var builder = WiredApp.CreateBuilder();
  8. await builder
  9. .Endpoint(IPAddress.Any, 8080)
  10. .MapGet("/plaintext", scope => context =>
  11. {
  12. context
  13. .Respond()
  14. .Status(ResponseStatus.Ok)
  15. .Content(new StringContent("Hello, World!"))
  16. .Type("text/plain");
  17. })
  18. .MapGet("/json", scope => context =>
  19. {
  20. context
  21. .Respond()
  22. .Status(ResponseStatus.Ok)
  23. .Content(new JsonContent(new
  24. {
  25. Message = "Hello, World!"
  26. }, JsonSerializerOptions.Default))
  27. .Type("application/json");
  28. })
  29. .Build()
  30. .RunAsync();