Closed pubpy2015 closed 3 years ago
I saw this article: https://scottoffen.github.io/grapevine/docs/routes
If the method is omitted, the route is assigned the default method HttpMethod.Any, which, as the name suggests, will match any HTTP method.
We could use "Any" or HttpMethod.Any enum when specifying the route.
I guess that would work. Since that matches any methods, if you want it to specifically match only GET and POST methods, maybe could do some branching in the method assigned to the route to check the method from the context
.
Hope it helps.
Thank you very much.
You can also use multiple Route
attributes on the method.
[RestRoute("Get", "/hello")]
[RestRoute("Post", "/hello")]
public async Task HelloWorld(IHttpContext context)
{
await context.Response.SendResponseAsync($"Hello, world!");
}
However, you would have to differentiate in the method if you want the behavior to change depending on whether the method is POST
or GET
.
Thanks,
An other question:
I am building a server on my PC (IP address of my PC is: 192.168.100.92) as:
string _serverPort = "1122";
var server = RestServerBuilder.UseDefaults().Build();
server.Prefixes.Add($"http://localhost:{_serverPort}/");
server.Start();
but when trying access to http://127.0.0.1:1122/api/test or http://192.168.100.92:1122/api/test i get the result is:
only when access to http://localhost:1122/api/test i get the corect result:
How to solve this problem ?
On your V4, I can do all with:
server.Host = "+";
server.Port = 1122;
server.Start();
Oh,
seem replace "localhost" by "+" will solve this problem:
server.Prefixes.Add($"http://+:{_serverPort}/");
In Grapevine V4, i can do that: