ExpressWebJs 3.2 Released
Chukwuemeka Igbokwe
Posted on September 19, 2021
The ExpressWebJs team have released 3.2 with auto endpoint documentation, and improvement in service injection.
Auto Endpoint Documentation:
Reference documentation for API endpoints consists of five general sections: resource descriptions, endpoints and methods, parameters, sample requests, and sample responses and schemas. All these are auto documented for you while you code, to allow you focus on building your amazing application.
To get started, install ExpressWebJs by running the command below
npx expresswebcli new MyApplication --ts
and run 'npm install' to install the node packages 📦. Then create few endpoints and visit your base url in a browser followed by /documentationView for HTML view or /documentationJson for JSON.
Example: http://127.0.0.1:5000/documentationView or http://127.0.0.1:5000/documentationJson.
Service Injection
You can now inject services irrespective of the order in the application context.
In our Application Service Provider register method, we've registered some services.
public register() {
this.app.singleton("UserService", UserService, "class");
this.app.singleton("CompanyService", CompanyService, "class");
this.app.singleton("FolderService", FolderService, "class");
}
Now we can inject UserService into FolderService like so:
import FolderRepository from "App/Repository/FolderRepository";
import BaseService from "../BaseService";
import IFolderService from "./IFolderService";
import IUserService from "./IUserService";
class FolderService extends BaseService implements
protected userService:IUserService
constructor(UserService:IUserService){
this.userService = UserService
}
IFolderService {
async getSubFolders(user_id: string): Promise<object> {
return await new Promise(async (resolve, reject) => {
try {
let data = await new userService().findById(user_id);
...
} catch (error: any) {
...
}
});
}
}
You can join ExpressWebJs community on Discord and don't forget to give us a star on github
ExpressWebJs Javascript and ExpressWebJs Typescript
Posted on September 19, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.