SaturnFramework / Saturn

Opinionated, web development framework for F# which implements the server-side, functional MVC pattern
https://saturnframework.org
MIT License
703 stars 108 forks source link

Incorrect forwarding with common root at the same level #346

Open 0-gravity opened 2 years ago

0-gravity commented 2 years ago

Incorrect forwarding with common root at the same level for example next routing will fail router { forward $"/roots" (text "roots") forwardf "/roots/%O" (sprintf "roots/%O" >> text) }

0-gravity commented 2 years ago

In my opinion all formatted paths should come before normal ones, which means: getf/postf/patchesf/putsf/deletef should come before get/post/patches/puts/delete

Banashek commented 1 year ago

I believe there are cases where a concrete path would be desired to have precedence. Say part of your route path is fuzzy, but in certain concrete cases you want it to go to a specific page.

Hypothetical Example:

One might want the featured products to go to a special page formatted for display, whereas the application might also support user-generated tags for products, which could show on a default display.

While this could also be done within the handler logic itself (which I think would be better in most cases), there may be other complicating logic which determines the route to be the cleanest spot to separate the branches at.

Just thinking out loud here, but how would that be doable with this new routing?

0-gravity commented 1 year ago

It works just fine, unless I missed some cases. Here is an example: `open Saturn open Giraffe

let apiRouter = router { get "/products/featured/catalog" (text "/products/featured/catalog - non-parametrized") getf "/products/%s/catalog" (sprintf "/products/%s/catalog - parametrized" >> text) }

let appRouter = router { forward "/api" apiRouter }

let app = application { disable_diagnostics use_router appRouter url "http://0.0.0.0:8085/" }

run app`

I could not come up with an example in which request may fail. I'd be happy to see one

Banashek commented 1 year ago

No you're right that looks to be the correct behavior. I should have pulled down the branch and tested myself rather than trying to eyeball the code. Thanks for providing the test!

64J0 commented 1 year ago

In my opinion all formatted paths should come before normal ones, which means: getf/postf/patchesf/putsf/deletef should come before get/post/patches/puts/delete

I did not get this @0-gravity. Why you make this proposition?

It appears that you want to make generic paths to be evaluated before specific paths. I don't think this is a good idea.