/ng-hal

A navigator for HAL documents in Angular

Primary LanguageTypeScriptMIT LicenseMIT

ng-hal

npm version npm downloads License Dependencies Status Peer Dependencies Status

Greenkeeper CircleCI Travis CI Codecov coverage on master

A navigator for HAL documents in Angular

Usage

$ npm install --save ng-hal

Alternative, use yarn:

$ yarn add ng-hal

Import HalModule.forRoot() to your application's module:

import { HalModule } from 'ng-hal';

@NgModule({
  imports:      [
    HttpModule,
    HalModule.forRoot()
  ]
})
export class AppModule {}

Inject Navigator into components or services, then start retrieving HAL/JSON documents:

import { Navigator } from 'ng-hal';

@Injectable()
export class Foo {

  constructor(
    private navigator: Navigator
  ) {}

  demo() {
    this.navigator
      .get('/my/hal-document.json')
      .subscribe((doc: Document) => console.log(doc));
  }
}

Demo application

http://spektrakel.de/ng-hal

API Design Considerations

  • Navigator API is almost identical to Angular's Http API.
    • follow is a short-cut Observable operation that is derived from mergeMap/flatMap.
  • Document gives you a Resource object and the original Request/Response pair.
  • Resource is a normalized view of the JSON document. You can, however, obtain the unmodified JSON object.

Reading List

Credits