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
Add grouping route #32
Comments
Hey @Nosthertus pretty good idea! |
great.. i came up with this when i was developing |
Syntactically, I think an event emitter would be a better option, example:
|
@mnzt that is also a good idea. there could also be a function to catch all methods at once |
At present i group it like this: I create out of diet.js a server framework to listen for many thousend apps and domains. for my usecase maybe you can use that infos: i do for the main server a global.server = diet then in the main server i do server.controller('app1') so app1 needs top be a js file that defines a normal dietjs app and use a costum name for the server object. like app1= require diet () so app1 is the complet app group that is complet configured when i now whant to use that for a domain i only need to do in the main server index.js where we started app1.listen('protocol://rest') i can repeat that many 1000 times or simply let app1-4 listen for diffrent groups of domains. then you create middelware functions so you can reuse the methods in all your apps and combine them so to groups. greetings. |
Hey guys, love this topic. I will add this feature in the upcoming The API will most probably be like this: var book = app.resource('/book')
book.post(function($){ ... })
book.put(function($){ ... })
book.get(function($){ ... })
book.delete(function($){ ... }) This will allow chaining the method listeners as well: app.resource('/book')
.post(function($){ ... })
.put(function($){ ... })
.get(function($){ ... })
.delete(function($){ ... }) Kind Regards, |
@frank-dspeed can you share some code snippets for your implementation? |
i suppose |
Ya need to find the example have at present to much un sorted codes but will ping you back on this and will always watch this repo for current state |
I changed the source code and I implemented this for me, and it is working very well. app.group('/api/v1').then( route => {
route('get', '/home', $ => { $.end(`User Home`) });
route('post', '/insert', $ =>{ $.end(`Insert an User`) });
});
app.group('/api/v2').then( route => {
route('get', '/home', $ => { $.end(`User Home v2`) });
route('get', '/contact', $ => { $.end(`User Contact v2`) });
}); |
I created a grouping route module for |
- Introducing the app.resource(path) class for grouping methods - inner functionality inspired by @luisvinicius167 's diet-group-router #32
As of var book = app.resource('/book')
book.post(function($){ ... })
book.put(function($){ ... })
book.get(function($){ ... })
book.delete(function($){ ... }) You can also chain it as such: app.resource('/book')
.post(function($){ ... })
.put(function($){ ... })
.get(function($){ ... })
.delete(function($){ ... }) For reference check out the Resource Example: |
should i send a pull request of this in diet docs? or are you planning to add this in the docs at some time? |
@Noshertus you can open a issue to add that to the docs but i think it has no core priority |
Could be a nice idea.. but what if there was a function that groups all methods in a single route?
for example:
The text was updated successfully, but these errors were encountered: