TFRES.Core 1.0.0

tiny, fast... REST-endpoint Server - based on jchristn/WatsonWebserver

Install-Package TFRES.Core -Version 1.0.0
dotnet add package TFRES.Core --version 1.0.0
<PackageReference Include="TFRES.Core" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TFRES.Core --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
  using System;
  using Newtonsoft.Json;
  using Tfres;
  
  namespace Application
  {
    static class Program
    {
      static void Main(string[] args)
      {
        Server s = new Server("127.0.0.1", 9000, DefaultRoute);
  
        // add static routes
        s.AddEndpoint(HttpVerb.GET, "/helloWorld/", GetHelloRoute);
        s.AddEndpoint(HttpVerb.GET, "/jsonObj/", GetJsonObjRoute);
        s.AddEndpoint(HttpVerb.POST, "/sayHello/", PostSayHelloRoute);
  
        Console.WriteLine("Press ENTER to exit");
        Console.ReadLine();
      }
  
      static HttpResponse DefaultRoute(HttpRequest req)
        => new HttpResponse(req, true, 200, null, "text/plain", "Hello from the default route!");
  
      static HttpResponse GetHelloRoute(HttpRequest req)
        => new HttpResponse(req, true, 200, null, "text/plain", "Hello from the GET /hello static route!");

      private static HttpResponse GetJsonObjRoute(HttpRequest req)
        => new HttpResponse(req, true, 200, null, "application/json", 
                            JsonConvert.SerializeObject(new Person { Name = "Jan", Animals = 1 }));
      
      static HttpResponse PostSayHelloRoute(HttpRequest req)
        => new HttpResponse(req, true, 200, null, "text/plain", $"Hello {req.PostData<Person>().Name}!");
    }
  
    public class Person
    {
      public string Name { get; set; }
      public int Animals { get; set; }
    }
  }
  using System;
  using Newtonsoft.Json;
  using Tfres;
  
  namespace Application
  {
    static class Program
    {
      static void Main(string[] args)
      {
        Server s = new Server("127.0.0.1", 9000, DefaultRoute);
  
        // add static routes
        s.AddEndpoint(HttpVerb.GET, "/helloWorld/", GetHelloRoute);
        s.AddEndpoint(HttpVerb.GET, "/jsonObj/", GetJsonObjRoute);
        s.AddEndpoint(HttpVerb.POST, "/sayHello/", PostSayHelloRoute);
  
        Console.WriteLine("Press ENTER to exit");
        Console.ReadLine();
      }
  
      static HttpResponse DefaultRoute(HttpRequest req)
        => new HttpResponse(req, true, 200, null, "text/plain", "Hello from the default route!");
  
      static HttpResponse GetHelloRoute(HttpRequest req)
        => new HttpResponse(req, true, 200, null, "text/plain", "Hello from the GET /hello static route!");

      private static HttpResponse GetJsonObjRoute(HttpRequest req)
        => new HttpResponse(req, true, 200, null, "application/json", 
                            JsonConvert.SerializeObject(new Person { Name = "Jan", Animals = 1 }));
      
      static HttpResponse PostSayHelloRoute(HttpRequest req)
        => new HttpResponse(req, true, 200, null, "text/plain", $"Hello {req.PostData<Person>().Name}!");
    }
  
    public class Person
    {
      public string Name { get; set; }
      public int Animals { get; set; }
    }
  }

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.0 135 1/3/2019