Justin Dearing
Justin Dearing

Reputation: 14978

Having multiple optional segments in a NancyFX Route

I have the following route in NancyFX:

Get["/Foo/{A?}/{B?}/{C?}"] = request => {  /* some stuff */ };

It responds to http://localhost:1234/Foo/ amd http://localhost:1234/Foo//1/2/3/ but not http://localhost:1234/Foo/1/ and http://localhost:1234/Foo/1/2/. Basically you have to include all or none of the optional segments.I know I could use multiple segments, but how can I make each segment individually optional, and only dependent on the preceding segments?

Upvotes: 1

Views: 570

Answers (1)

Michal Dymel
Michal Dymel

Reputation: 4360

You can do it like this:

Get["/Foo/{A?}"] = 
Get["/Foo/{A?}/{B?}"] = 
Get["/Foo/{A?}/{B?}/{C?}"] = request => {  /* some stuff */ };

Upvotes: 4

Related Questions