kevelopment / haruJs

JavaScript Web Framework built in TypeScript bringing in some Spring feelings.
0 stars 0 forks source link

Add @RequestParam Decorator #14

Open kevelopment opened 3 years ago

kevelopment commented 3 years ago

Corresponding Java/Spring example:

@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
  return String.format("Hello %s!", name);
}

Might be a good idea to abstract Middlewares in such a way that if a @RequestParam is declared, only specified params will be given to a method and e.g. return next() will be called automatically afterwards.

Internal Call

const requestParam = ({value, default}) => {
  return (target, propertyKey, descriptor) => {
      // some other important stuff happening beforeHand of course
      app.get('/hello', (ctx,next) => {
        // get Param from ctx and set default if none
        const param = ctx.params[value] ?? default;
        // actual method call
        component[propertyKey](ctx.params['name'] 
        // call next middleware
        return next();
      });
  }
};