I would like to have the same action be performed by 2 or more route patterns.
For example:
//Route 1:
Get["/{category}/{product_name}/{id}"]
// Route 2:
Get["/api/products/{id}"]
Ideally the first route would be SEO friendly and return a view, the second route would return JSON and be used as an API.
Is it simply a matter of defining 2 separate routes and calling the common logic encapsulated in another method? Or is there some Nancy magic I don't know about?
Update My final solution was to use multiple assignments in the one statement.
Get["/{category}/{product_name}/{id}"] = Get["/api/products/{id}"] = params =>
{
...
};
I know this is answered, but I thought I'd add my tuppence for a slightly neater solution. This is my solution:
public class ExampleModule : NancyModule
{
public ExampleModule()
{
Get["/somepath"] = DoSomething;
Post["/somepath"] = DoSomething;
}
private dynamic DoSomething(dynamic parameters)
{
return null;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With