DEV Community

NotFound404
NotFound404

Posted on

Three steps to start your restful api server with aex

Aex is a web framework focus on productivity. With Aex, you can do more with less code.
if you want to write restful api, you normally would always do some dirty initialization works.
now aex provides a way to make restful api development a little more painless with node.js.
Here is how.

1. Restful API Class with @rest decorator to one of it's member functions.

import {rest} from "@aex/core"
class UserAPI {
@rest("/users")
 public road(ctx: any) {
 // this function default used for get method if you don't define a get method.
 }
Enter fullscreen mode Exit fullscreen mode

2. Add corresponding methods

Currently aex supports "get", "put", "post", "patch", "delete", these five methods. all this methods should be async and default to compact mode.

import {rest} from "@aex/core"
class UserAPI {
@rest("/users")
public road(ctx: any) {
}
public async post(ctx:any) {
}
Enter fullscreen mode Exit fullscreen mode

3. start aex server

import {Aex} from "@aex/core"
const aex = new Aex();
aex.push(UserAPI);
aex.prepare().start(8080).then(() => {});

Enter fullscreen mode Exit fullscreen mode

For detailed usage or update, please visit the aex repo:
https://github.com/calidion/aex

Top comments (0)