Working on a client code generation feature to help speed up using an api built with this library.

This commit is contained in:
2023-02-03 13:33:28 -08:00
parent f8704e425b
commit 19ccdb9026
5 changed files with 522 additions and 1 deletions

View File

@ -34,6 +34,10 @@ namespace MontoyaTech.Rest.Net.Example
new Route(HttpRequestMethod.Get, "/json", Json)
);
Console.WriteLine(CodeGenerator.GenerateCSharpClient(listener.Routes));
Console.ReadLine();
listener.RequestPreProcessEvent += (HttpListenerContext context) => {
Console.WriteLine("Request start: " + context.Request.RawUrl);
return true;
@ -56,21 +60,25 @@ namespace MontoyaTech.Rest.Net.Example
listener.Block();
}
[RouteGroup("Test")]
public static HttpListenerResponse Status(HttpListenerContext context)
{
return context.Response.WithStatus(HttpStatusCode.OK).WithText("Everything is operational. 👍");
}
[RouteGroup("Test")]
public static HttpListenerResponse Add(HttpListenerContext context, double a, double b)
{
return context.Response.WithStatus(HttpStatusCode.OK).WithText((a + b).ToString());
}
[RouteGroup("Test")]
public static HttpListenerResponse Signup(HttpListenerContext context, User user)
{
return context.Response.WithStatus(HttpStatusCode.OK).WithText("User:" + user.Name);
}
[RouteGroup("Test")]
public static HttpListenerResponse Json(HttpListenerContext context)
{
return context.Response.WithStatus(HttpStatusCode.OK).WithJson(new User("Rest.Net"));