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'sHttp
API.follow
is a short-cut Observable operation that is derived frommergeMap
/flatMap
.
Document
gives you aResource
object and the originalRequest
/Response
pair.Resource
is a normalized view of the JSON document. You can, however, obtain the unmodified JSON object.
- HAL - Hypertext Application Language: specification
- JSON Hypertext Application Language: draft-kelly-json-hal-08
- URI Templates: RFC 6570
- basti1302/halfred: resource parsing and normalization for
application/hal+json
- geraintluff/uri-templates: URI templates according to RFC6570
- Daniel Rosenwasser: for helping out on TypeScript #10463