3. SDK Components

Jonathan Casarrubias edited this page Sep 10, 2016 · 5 revisions

LoopBack SDK Builder

Services, Interfaces and Models (SIM)

When generating your SDK; The LoopBack SDK Builder will create a SIM set for each Model you have defined in your LoopBack Application.

Services

Services are regular Angular 2 @Injectable() Services that allows you to interact with your API either through standard RESTful communication, WebSockets or even Server Sent Events. Real-time with no excuses.

Interfaces

Will declare all of the model properties defined in your LoopBack Application, it will even set these as optional or required according your model configuration.

Models

Models are regular classes that will implement the model Interface and a constructor that allows to extend models to provide custom functionality.

Models and Interfaces are a set of TypeScript Declaration Files.

Naming Convention

While generating your SDK; the LoopBack SDK Builder will create each of these components for each Model you have defined in your LoopBack Application.

  • Services.- Adds an Api postfix to the Model name.
  • Interfaces.- Adds an Interface postfix to the Model name.
  • Model.- Is just the Model name.

Logger Service

The LoggerService is a tool that wraps the console methods (log, info, warn, error, count, group, profile, etc.) but allowing you to disable/enable your logs for development/production mode.

import { LoopBackConfig, LoggerService } from './shared/sdk';
...
class MyComponent {
  constructor(private log: LoggerService) {
    LoopBackConfig.setDebugMode(false); // defaults true
    this.log.info('Component is Loaded');
  }
}