ngx-hal
TypeScript icon, indicating that this package has built-in type declarations

3.2.0 • Public • Published

NgxHal

ngx-hal is a data store with a support for handling HAL formatted HTTP requests.

Features

  • GET single resource
  • GET list of resources

Installation

npm install --save ngx-hal

Basic usage

After the initial ngx-hal setup (see Getting started section) you have to create a resource model which extends HalModel from the ngx-hal and a resource service which extends ModelService from ngx-hal. The following example uses User resource as an example.

user.model.ts

class User extends HalModel {
  @Attribute()
  public name: string;
}

user.service.ts

class UserService extends ModelService<User> {
	constructor(datastore: DatastoreService) {
		super(datastore, User);
	}
}

And then a few methods are available on an instance of UserService:

Fetching a user

this.userService.find('1').subscribe((user: User) => {
	console.log('Fetched user', user);
});

Fetching a list of users

this.userService.find().subscribe((users: Array<User>) => {
	console.log('Fetched users', users);
});

Fetching a list of users with pagination information

this.userService.find({}, true).subscribe((halDocument: HalDocument<User>) => {
	console.log('Fetched users', halDocument.models);
	console.log('Pagination information', halDocument.pagination);
});

API reference

Build

ng build

Running unit tests

ng test

Readme

Keywords

Package Sidebar

Install

npm i ngx-hal

Weekly Downloads

66

Version

3.2.0

License

MIT

Unpacked Size

791 kB

Total Files

142

Last publish

Collaborators

  • safo6m