A navigator for HAL documents in Angular
A navigator for HAL documents in Angular
$ 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));
}
}
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.application/hal+json