DEV Community

NotFound404
NotFound404

Posted on

Using Compact Mode with Aex v0.18.0

Traditionally we handle http request with a callback have parameters named:
request, response, next or something.
In Aex, we use :

req, res, scope
Enter fullscreen mode Exit fullscreen mode

where scope is a data carrier for the request.

The following is the traditional http handler in aex:

class User {
@http("get", "/user/login")
public async login(req, res, scope) {
}
}
Enter fullscreen mode Exit fullscreen mode

in aex v0.18.0, we introduced the compact mode, where we can use only one variable if others are not needed.

Here is the compact mode http handler in aex:

class User {
@http("get", "/user/login", true)
public async login(context) {
  const {req, res, scope} = context;
  const res = context.res;
}

@compact("get", "/user/login")
public async compact(context) {
  const {req, res, scope} = context;
  const res = context.res;
}
}
Enter fullscreen mode Exit fullscreen mode

It wraps all variables into one context object.

So you can choose a tidy one for your programs for certain development stages.

You can start with compact mode then to the traditional mode or traditional mode to compact mode.

You can try it with :

npm install github:calidion/aex#v0.18.0
Enter fullscreen mode Exit fullscreen mode

Top comments (0)