Program.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Buffers.Text;
  3. using System.Net;
  4. using System.Threading.Tasks;
  5. using SimpleW;
  6. namespace Benchmarks;
  7. internal static class Program
  8. {
  9. public static async Task Main(string[] args)
  10. {
  11. var server = new SimpleWServer(IPAddress.Any, 8080);
  12. server.AddDynamicContent("/api");
  13. server.Start();
  14. await Task.Delay(-1);
  15. }
  16. public class BenchmarksController : Controller {
  17. [Route("GET", "/json")]
  18. public object Json() {
  19. return Response.MakeResponse(
  20. new { message = "Hello, World!" }, // object will be serialized
  21. addHeaders: new Dictionary<string, string>()
  22. {
  23. { "Server", "SimpleW" },
  24. { "Date", DateTime.Now.ToString("R") }
  25. }
  26. // compress parameter is default to null, so no compression
  27. );
  28. }
  29. [Route("GET", "/plaintext")]
  30. public object Plaintext() {
  31. return Response.MakeResponse(
  32. "Hello, World!",
  33. "text/plain",
  34. addHeaders: new Dictionary<string, string>()
  35. {
  36. { "Server", "SimpleW" },
  37. { "Date", DateTime.Now.ToString("R") }
  38. }
  39. // compress parameter is default to null, so no compression
  40. );
  41. }
  42. }
  43. }