1.4.31 • Published 4 years ago

ac-api-framework v1.4.31

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

API Framework

Install it as a module in your API server project.

Preparation

Create folders

  • api/controllers
  • api/models
  • api/policies
  • api/services

Local configuration

If you want to use local configuration (which is recommended), create a folder config/env and put files named like the environment in it (e.g. development.js, test.js, production.js).

Bootstrap

Create a file "bootstrap.js" in api root folder and add all initializing functions (Redis, ES etc) there.

Controller

Create you first controller in api/controllers folder. Use the "BootstrapController.js" from this package as template.

Models

TBC

Services

TBC

Policies

ExpressJS-like middleware

Logging

Winston is available for logging. It is recommended to use ac-logger package for even more unified logging.

Add-ons

Sanitizer

By default a sanitizer to check and sanitize the incoming payload is activated. You can disable it on per-route basis. The sanitizer checks against a field definition (config path apiDoc). See example for sanitizer and apiDoc below.

API Documentation

By default the API Documentation is enabled. You can disable it on per-route basis. The API documentation plugin creates a JSON documentation for a given controller based on apiDoc definition at config.apiDoc.CONTROLLER.

If you send the header x-ac-apiDoc = true to a controller-action path, you will receive the documentation response.