Provider Specification - Routes and Controllers

Provider-specific routes

In addition to routes defined by output-plugins, a provider may extend the Koop API by defining their own routes and associated controllers. These routes are defined in a file that is referenced in the registration object. This file should export an array of route definition objects. Each object must have:

property name type description example
path string An Express.js style route that includes optional parameters /provider-name/:id/metadata
methods string[] HTTP methods that should be handled at this route [get, post]
handler string Name of the controller function in controller file that should handle requests at this route metadataHandler
module.exports = [
    path: `/provider-name/:id/metadata`,
    methods: ['get'],
    handler: 'metadataHandler'
Figure 1. Contents of a routes.js file that defines a single provider-specific route.


Each route defintion has a handler property that should name a method to be used for route handling. You can define these methods on a Controller class in a file that must be properly referenced in the registration object.

function Controller (model) {
  this.model = model

Controller.prototype.test = function (req, res) {
  res.status(200).json({ version: '1.0.0' })

module.exports = Controller
Figure 2. Contents of a controllers.js file that defines a `Controller` class with methods that act as handler for provider-specific routes.

Improve this page