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

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs