Working on C# client code generation.
This commit is contained in:
47
Rest.Net.Example/Client.cs
Normal file
47
Rest.Net.Example/Client.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MontoyaTech.Rest.Net.Example
|
||||
{
|
||||
public class Client
|
||||
{
|
||||
public string BaseUrl = null;
|
||||
|
||||
public TestFunctions Test;
|
||||
|
||||
public class TestFunctions
|
||||
{
|
||||
public Client Client;
|
||||
|
||||
public TestFunctions(Client client)
|
||||
{
|
||||
this.Client = client;
|
||||
}
|
||||
|
||||
public void Status()
|
||||
{
|
||||
}
|
||||
|
||||
public void Add()
|
||||
{
|
||||
}
|
||||
|
||||
public void Signup()
|
||||
{
|
||||
}
|
||||
|
||||
public void Json()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public Client(string baseUrl)
|
||||
{
|
||||
this.BaseUrl = baseUrl;
|
||||
this.Test = new TestFunctions(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -34,7 +34,9 @@ namespace MontoyaTech.Rest.Net.Example
|
||||
new Route(HttpRequestMethod.Get, "/json", Json)
|
||||
);
|
||||
|
||||
Console.WriteLine(CodeGenerator.GenerateCSharpClient(listener.Routes));
|
||||
string code = CodeGenerator.GenerateCSharpClient(listener.Routes);
|
||||
|
||||
Console.WriteLine(code);
|
||||
|
||||
Console.ReadLine();
|
||||
|
||||
@ -61,24 +63,35 @@ namespace MontoyaTech.Rest.Net.Example
|
||||
}
|
||||
|
||||
[RouteGroup("Test")]
|
||||
[RouteResponse(typeof(string))]
|
||||
public static HttpListenerResponse Status(HttpListenerContext context)
|
||||
{
|
||||
return context.Response.WithStatus(HttpStatusCode.OK).WithText("Everything is operational. 👍");
|
||||
}
|
||||
|
||||
[RouteGroup("Test")]
|
||||
[RouteResponse(typeof(string))]
|
||||
public static HttpListenerResponse Add(HttpListenerContext context, double a, double b)
|
||||
{
|
||||
return context.Response.WithStatus(HttpStatusCode.OK).WithText((a + b).ToString());
|
||||
}
|
||||
|
||||
[RouteGroup("Test")]
|
||||
[RouteResponse(typeof(string))]
|
||||
public static HttpListenerResponse Signup(HttpListenerContext context, User user)
|
||||
{
|
||||
return context.Response.WithStatus(HttpStatusCode.OK).WithText("User:" + user.Name);
|
||||
}
|
||||
|
||||
[RouteGroup("Test")]
|
||||
[RouteRequest(typeof(User))]
|
||||
public static HttpListenerResponse SignupRequest(HttpListenerContext context)
|
||||
{
|
||||
return context.Response.WithStatus(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
[RouteGroup("Test")]
|
||||
[RouteResponse(typeof(User))]
|
||||
public static HttpListenerResponse Json(HttpListenerContext context)
|
||||
{
|
||||
return context.Response.WithStatus(HttpStatusCode.OK).WithJson(new User("Rest.Net"));
|
||||
|
Reference in New Issue
Block a user