New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

angular-json-rest-service

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-json-rest-service

Provides a simple active record factory wrapper service over a remote JSON ReST service for NG2

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

Overview

This package provides a simple Angular 2 service JsonRestService, which is a wrapper of @angular/http/Http.

JsonRestService expects the remote HTTP service to be a ReST service taking and returning JSON with the usual semantics. JsonRestService will hydrate records it pulls off the wire into a user defined class implementing ActiveRecord. Model implements a very basic ActiveRecord you can use as a base and extend.

JsonRestService is generic like this: JsonRestService<T extends ActiveRecord>. In order to dynamically create instances of type T (for get(), and find()), the JsonRestService constructor also requires an instance of ActiveRecordFactory<T>.

Synopsis

import { Component } from '@angular/core';
import { Http } from '@angular/http';
import 'angular-json-rest-service/rxjs-extensions';
import { JsonRestService, ActiveRecordFactory } from 'angular-json-rest-service/json-rest.service';
// Base implementations of ActiveRecord / ActiveRecordFactory interfaces.
import { Model } from 'angular-json-rest-service/model';

class Hero extends Model {
  name: string;
  power(): number {
    return 69;
  }
}

class HeroFactory extends ActiveRecordFactory<Hero>
{
  create(object: Object, storage: JsonRestService<Hero>): Hero {
    var model = new Hero(storage)
    model.merge(object)
    return model;
  }
}

@Component({
    selector: 'my-app',
    template: `<h1>Hello {{hero.name}}. Your power is {{hero.power()}}</h1>`
})
export class AppComponent {
  hero: Hero;
  constructor(private http:Http) {
    var myService = new JsonRestService<Model>(
      http,
      '/root/heroes',
      new HeroFactory()
    )
    this.hero = new Hero(myService)
    myService.find().toPromise().then((m: Hero[]) => {
      this.hero = m[0];
      console.log(m.map(n => n.toJson()))
    })
  }
}

Keywords

ng2

FAQs

Package last updated on 28 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts