-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nesting path combinators #570
Comments
Not a Suave expert, but if I understand correctly, you simply want something like: let apiPath = ((+) "/api") >> path So you can do choose [ apiPath "" >=> NO_CONTENT; apiPath "/users" >=> OK "...json..." ] Later maybe you'd extend your |
@caindy Thanks for the suggestion, but there would still be some duplication within a developer's application that could stand to be removed. A developer need to create and manage these helper functions, so a benefit here would be reducing the amount of code the developer's application would need to hold itself. |
Are you looking for something like Express.js's router/module paradigm? (briefly described here) Something like... let apiRoutes =
router [
routePath "/" >=> NO_CONTENT
routePath "/users" >=> OK """{"api": "users"}"""
]
let app =
choose [
path "/" >=> OK "index"
path "/api" >=> apiRoutes
] |
I too found this to be a minor let down. However, I (am no way a Suave expert) can see why |
+1 to PRs where we can discuss this over code. |
As a newcomer to Suave, I've been working to move past copying and pasting examples I come across, and I've started building an application from scratch. During this process, I attempted to do something like this:
expecting a request to
/api
would return a204 No Content
response and a request to/api/users
would return the JSON-encoded string. To my surprise, I received a404 Not Found
for both. After doing some digging, I discovered thatpath
tests if the given path matches the request path, so withpath "/users"
above, it compares a request to/api/users
with the given/users
, fails, and returnsNone
.I wasn't able to find anything in the existing code base to handle this, so I added the following as a helper module in my application to achieve the expected behavior:
allowing the following to work as expected:
I took to Twitter to see if there was an official way of doing this, and the official Twitter handle suggested I open a PR to start a discussion (see: https://twitter.com/SuaveIO/status/823219104995741696). I'm a a big fan of using issues for these types of discussions, but if something like the above is desired for Suave, I'd be happy to submit a PR for any changes.
Does something like this exist today? If not, would it be useful to include this functionality as a part of Suave?
The text was updated successfully, but these errors were encountered: