Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Conversation

TuckerCowie
Copy link

Given a swagger config:

  "paths": {
    "/pets/{id}": {
      "get": {
        "operationId": "getPetsById",
      }
    }
  }

and a router config:

{
  swaggerRouterOptions: {
    controllers: './controllers'
  }
}

and the following directory structure:

controllers/
`-- Pets/
    `-- getPetById.js

This request will invoke getPetById as a function

GET /api/pets/123
200

Otherwise, all preexisting functionality is present.

@JonClayton
Copy link

JonClayton commented Jan 27, 2017

This is pretty cool since it allows easier separation of the individual endpoint handling functions without an artificial and long top level controller file

@whitlockjc
Copy link
Member

So you want to break down the controller into separate, per-handler files?

@TuckerCowie
Copy link
Author

Correct. In a microservice architecture or in servers that only have one top level business concept, certain routes may implement some middleware and utilities while others may not. In our use case sometimes we are dealing with CRUDing basic JSON resources, while other times we are exposing business logic through an endpoint. Splitting the controlling logic into per-handler files helps alleviate unnecessary overhead for those routes that do not share any implementation details even though they may share a common parent route.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants