Entry Point
Plumier application is the entry point of all Plumier based API. Creating Plumier application simply by creating instance of Plumier
class. The simplest Plumier application at least must have WebApiFacility
installed like below.
By default Plumier will search for controllers using this glob pattern ./**/*controller.+(ts|js)
or ./**/*entity.+(ts|js)
, its mean it will search for all TypeScript/JavaScript files ends with controller
or entity
(for first class entity). It also automatically detected exported controller in the same file with the entry point file, this is useful for single file project.
Above configuration does noting because no controller specified. We can start above code using ts-node or ts-node-dev, by specify it on the package.json
script like below.
#
FacilitiesPlumier application is configurable using facility, facility is a framework component consist of configurations, ordered middlewares and some micro process before the framework started.
There are list of built-in facility that ready to be used.
Facility | Includes | Package |
---|---|---|
WebApiFacility | Body parser, CORS middleware, Default dependency resolver | plumier |
RestApiFacility | Same as WebApiFacility except its provided more strict restful API status code | plumier |
ControllerFacility | Host controllers by path or type, furthermore controllers can be grouped and versioned | plumier |
LoggerFacility | Simple request logging and error reporting | plumier |
JwtAuthFacility | Jwt middleware, Enable authorization, Jwt Secret configuration | @plumier/jwt |
MongooseFacility | Mongoose schema generator, generic controller and connection management | @plumier/mongoose |
TypeORMFacility | Provided helper and generic controller for TypeORM | @plumier/typeorm |
ServeStaticFacility | Serve static files | @plumier/serve-static |
SwaggerFacility | Serve Swagger UI and generate Open API 3.0 automatically | @plumier/swagger |
FacebookOAuthFacility | Provide Facebook specific social login functionalities | @plumier/social-login |
GoogleOAuthFacility | Provide Google specific social login functionalities | @plumier/social-login |
GitHubOAuthFacility | Provide GitHub specific social login functionalities | @plumier/social-login |
GitLabOAuthFacility | Provide GitLab specific social login functionalities | @plumier/social-login |
TwitterOAuthFacility | Provide Twitter specific social login functionalities | @plumier/social-login |
#
Application For TestingWhen Plumier listen
method called immediately its make Plumier lost its ability for testing purpose. To do that you can use initialize
method to get a testable server like below.
By using code above, you can test your API using supertest like below.