using Tesses.WebServer;
using Tesses.WebServer.Swagme;
int value=0;
SwagmeServer svr=new SwagmeServer();
svr.AbsoluteUrl=true;
svr.Add("/Progress",async (e)=>{
await e.SendJsonAsync(new{Progress=50});
},new SwagmeDocumentation("Get Progress","Some progress in json"),group: "Getting Values");
svr.Add("/GetValue",async (e)=>{
await e.SendJsonAsync(new{num=value});
},new SwagmeDocumentation("Get Value","Value from SetValue?num=42 in json"),group: "Getting Values");
svr.Add("/SetValue",(e)=>{
string _va;
if(e.QueryParams.TryGetFirst("num",out _va))
{
int.TryParse(_va,out value);
}
},new SwagmeDocumentation("/SetValue?num=42","Set a number","Set an integer in program
"),group: "Setting Values");
svr.Add("/SetValue",(e)=>{
e.ParseBody();
string _va;
if(e.QueryParams.TryGetFirst("num",out _va))
{
int.TryParse(_va,out value);
}
},new SwagmeDocumentation("/SetValue?num=42","Set a number","Set an integer in program
"),"POST",group: "Setting Values");
svr.Add("/JsonEx",async(ctx)=>{
var req= await ctx.ReadJsonAsync();
string myMessage = $"{req.Name} {req.BeforeNumber} {req.NumberOfTimes} {req.AfterNumber}";
ExampleResponse resp=new ExampleResponse();
resp.Number = req.NumberOfTimes;
resp.YourMessage = myMessage;
await ctx.SendJsonAsync(resp);
},new SwagmeDocumentation("/JsonEx","Json Example Request Response",new ExampleRequest(),new ExampleResponse()),"POST","Json");
RouteServer rsvr=new RouteServer();
rsvr.Add("/",(e)=>{
e.SendText("Swagme TestSwagme Test
Api");
});
MountableServer mount =new MountableServer(rsvr);
mount.Mount("/api/",svr);
mount.StartServer(4202);