Lambda route example? #74
-
I'm trying to create routes with lambda, and here's what i've got. static void Main(string[] args)
{
Console.WriteLine("Hello World!");
var testRoute = new Route(async (context) =>
{
await context.Response.SendResponseAsync("Test");
}, "GET", "/text");
var server = RestServerBuilder.UseDefaults().Build();
server.Start();
Console.ReadLine();
} The route scanning is completed and found 0 routes. I'm pretty sure i am missing something, but i can't find any documentations or examples about creating and also using the route on the server. What is the correct way to use the lambda route? Edit: I tried doing this and it returns not implemented. static void Main(string[] args)
{
Console.WriteLine("Hello World!");
var testRoute = new Route(async (context) =>
{
await context.Response.SendResponseAsync("Test");
}, "GET", "/text");
var server = RestServerBuilder.UseDefaults().Build();
server.UseCorsPolicy();
server.Router.Register(testRoute);
server.Start();
Console.ReadLine();
} Thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Nevermind. Above code works, wonder why it didn't before. But I saw in the samples that the route is registered on AfterStarting event. Does it make any difference? Is it fine if i just register routes before starting? |
Beta Was this translation helpful? Give feedback.
Nevermind. Above code works, wonder why it didn't before. But I saw in the samples that the route is registered on AfterStarting event. Does it make any difference? Is it fine if i just register routes before starting?