Closed njlr closed 4 years ago
Suppose I divide my app into "regular" routes and "api" routes.
let api : WebPart = ... let regular : WebPart = ...
Then my app is a combination of the two:
app
let app = choose [ path "/api" api regular ]
The problem with this is that my api routes must be defined with /api in front:
api
/api
let api = choose [ path "/api/products" ... path "/api/users" ... ]
But I would prefer if the root of my api were defined outside and write my api like this:
let api = choose [ path "/products" ... path "/users" ... ]
I wrote a quick combinator that snips off the path before sending it on:
let takePath (path : string) (next : WebPart) : WebPart = fun context -> async { if context.request.path.StartsWith path then return! { context with request = { context.request with rawPath = context.request.path.Substring (path.Length) } } |> next else return None }
However, this seems like the sort of thing that would already be built in.
Is this implemented in Suave?
No, we do not have this implemented. There have been some discussions and proposals, you can find them in past issues.
https://github.com/SuaveIO/suave/issues/570
Thanks, didn't see those.
I will close my issue.
Suppose I divide my app into "regular" routes and "api" routes.
Then my
app
is a combination of the two:The problem with this is that my
api
routes must be defined with/api
in front:But I would prefer if the root of my api were defined outside and write my
api
like this:I wrote a quick combinator that snips off the path before sending it on:
However, this seems like the sort of thing that would already be built in.
Is this implemented in Suave?