Using Decorators in Express
See original GitHub issueI wanted Decorators to be part of Express restful API system, where you can define the url, method etc using decorators. This exist in Java Spring Framework like
@RestController
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
}
ref: https://spring.io/guides/gs/rest-service/
so in Express this
app.get('/greeting', function (req, res) {
res.send('Hello World!');
});
could convert to
@RestController()
class GreetingController() {
@Request('/greeting')
greeting(req, res) {
res.send('Hello World!');
}
}
This way a lot of Java Developers would be interested in NodeJS and Express environment and MEAN 2 would be great because Angular 2 also uses decorators 😄
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Express.js With Typescript Decorators in Examples - Medium
Let's take a look at how we can make our Express.js Server code cleaner with use of the Typescript Method Decorators.
Read more >@decorators/express - npm
node decorators - decorators for express library. ... Start using @decorators/express in your project by running `npm i @decorators/express` ...
Read more >How to Create Express Router Decorators with TypeScript
Class decorator: A controller decorator which handles base router information like path prefix, router-level middleware... Method decorator: A ...
Read more >Routing with TypeScript decorators for node applications
A guide on how to use TypeScript decorators to make routing in MVC frameworks (like expressjs) easier and more enjoyable.
Read more >OvernightJS: The best way to use ExpressJS with TypeScript
You may add routes to the controller by using decorators for Express GET, POST, PUT, and DELETE routes. Your method will work exactly...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mohammedzamakhan You could do it now, tho not with the syntax you’ve added here.
I’m not sure it’s really up to express to add that support, it’s more suited to a third party lib.
Ah, thanks guys 😃 So regardless of the merits of even handing decorators in Express, if it’s not even a part of core JavaScript, I don’t think now is the right time to support them.
FWIW, I did a quick Google and found https://www.npmjs.com/package/express-decorators which may do what you’re looking for @mohammedzamakhan