-
Notifications
You must be signed in to change notification settings - Fork 32
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
Router / Route Prefixing #554
Comments
Hum, we really don't have a way of "aggregate" endpoints, right? |
we don't and i don't even know how we'd put that in without bloating the code just to support a router. any thoughts @Guergeiro @ebebbington ? only way i can think of is pretty much going with the proposed approach in the discussion |
i dont think we should go naming something a Router because i think it'll just get confusing - it isnt really a router, the server/resources are the 'routers', the 'router' in this context is just a way to prefix multiple resources intto a group i've played around with it and came up with const server = new Server({
resources: [
{
prefix: "/api/v1",
resources: [Res],
}
],
protocol: "http",
hostname: "localhost",
services: [new CORSService({origin: 'google.com'})],
port: 3000,
}); Still toying with the idea, but another option could be like new Server({
resources: [...],
prefixes: [
{
prefix: "/api/v1",
resources: [HomeResource]
}
]
}) Then when we create the resources and the url pattern, we do something like this.#options.forEach(resourceClass => {
const prefixObj = this.#options.prefixes.find(p => p.resources.includes(resourceClass)) // <-- new code
let prefix= "" // <-- new code
if (prefixObj) prefix = prefixObj.prefix // <-- new code
const resource = new resourceClass();
const patterns: URLPattern[] = [];
resource.paths.forEach((path) => {
// Add "{/}?" to match possible trailing slashes too
patterns.push(new URLPattern({ pathname: prefix + path + "{/}?" })); // <-- added "prefix" part
});
}) |
There's only two ways I think would work without changing a lot of stuff.
|
i like ed's first way. that's clean. |
And the first approach of @ebebbington seems better. And would also add a global level prefix. |
first approach is hackier tho lol (to impl it internally) |
I get it... Is there a way of implementing a decorator pattern so that we don't change the logic of implementation? @crookse @ebebbington |
@ebebbington remember when i had the setUp method in Drash.Service? we could still introduce that and use a RouterService to rearrange the resources on setUp |
made a pr for documenting this on how a user can do it, as opposed to us writing the code: drashland/website-v2#47 @crookse do you know if we can contact the person that created the discussion? |
yea. replying now. |
hey @vosmith! we looked into this and there's actually nothing to implement since drash can be extended. here's an example of how to implement path prefixing: https://drash.land/drash/v2.x/tutorials/resources/prefixing-paths |
Discussed in https://github.com/drashland/drash/discussions/539
Originally posted by vosmith September 16, 2021
I happened to come across this project trying to figure out what Deno was and ended up finding Drash as one of the top web frameworks for Deno. I like the simplicity of the current API, but I was wondering if this project was interested in having some deeper support for request routing. Mainly, being able to mount a
Resource
, and its routes behind a prefix, or establishing a parent-child relationship between Resources. I felt that both of these could be accomplished with aRouter
or something similar.Here is a little better of an explanation. If I had 10 routes that all had a similar prefix like
/api/users
,/api/tasks
, etc. I would probably have aUsersResource
,TasksResource
, etc. If I ever wanted to change theapi
prefix toapi/v1
, I would need to update each file and fix the path. However, if I could move that prefix up a level, and declare my resources in a Router that has some parent path then I would only update the Router. Something like:Similarly, updating the
Resource
andServerConfigs
interface to includerouters: Drash.Interface.Router[]?
Again, I haven't had much experience with this framework and I don't really know how far the community is planning to take this project, but I thought I'd ask the question.
The text was updated successfully, but these errors were encountered: