lore-hook-connections

Allows you to describe the APIs your application will be consuming

Overview

New projects include a single connection named default, and the default config for new projects looks roughly like this:

module.exports = {

  default: {

    apiRoot: 'https://api.example.com',
    pluralize: true,
    casingStyle: 'camel',
    headers: function() {
      return {};
    },

    models: {
      properties: {
        parse: function(attributes) {
          return attributes;
        }
      }
    },

    collections: {
      properties: {
        parse: function(attributes) {
          return attributes;
        }
      }
    }

  }

};

The name for the connection (default) comes from the name of the key, and the config translates to this statement:

The API for the default connection is located at https://api.example.com. The names of the endpoints follow a camelCasing strategy and are pluralized. There are no default headers that need to be sent, and there is no need to parse the server response for any endpoints before we consume those resources in the application.

If you were interacting with a second API, such as GitHub's API, then you would create a second config for GitHub like this:

module.exports = {

  default: {
    // ...config options...
  },

  github: {

    apiRoot: 'https://api.github.com',
    pluralize: true,
    casingStyle: 'camel',

    collections: {
      properties: {
        parse: function(attributes) {
          return attributes.items;
        }
      }
    }

  }

};

Once again, the name for the connection (github) comes from the name of the key, and the config translates to this statement:

The GitHub API is located at https://api.github.com. The names of the endpoints follow a camelCasing strategy and are pluralized. When making requests to "collection" endpoints (like /repositories) the resources we want are stored inside the items attributes of the response.