lore-hook-connections

Allows you to describe the APIs your application will be consuming

Multiple Endpoints

Connections basically provide a way to store settings that should be applied to all models that communicate with a given endpoint. By default this connection is called default but you can rename it to whatever you want.

With this approach supporting multiple APIs is easy, as you can add additional connections and map them to models. For example, let's say we have an app developed using the default connection, and the API started migrating to v2. In this case, we could rename our default connection to v1 and add a second connection for v2 like this:

// config/connections.js
{
  v1: {...},
  v2: {...}
}

Then in config/models.js we rename the default connection and provide a map of which models use the non-default connection like this:

// config/models.js
{
  defaultConnection: 'v1',
  connectionModelMap: {
    // v1: [...optional...],
    v2: [
      'post',
      'comment',
      'modelThree'
    ]
  }
}

If you want to be explicit you can map all models, but models are assumed to be associated with the defaultConnection unless otherwise declared. This also gives a single location in the project to view which models are connected to which API endpoints.

Specify casing style of API servers

Currently the project assumes the API server uses a camelCase casing style, such as /api/userComments or/api/bookAuthors. But some APIs (like Django and Rails) use a snake_case style, like /api/user_comments, and others use a kebab-case style like /api/user-comments.

{
  camel: '/api/userComments',
  kebab: '/api/user-comments',
  snake: '/api/user_comments',
  pascal: '/api/UserComments'
}

Generally speaking, camel and pascal are the same thing, as URLs are case-insensitive, but the user way to prefer to see networks requests in one style of the other, so both are supported.