Socket
Socket
Sign inDemoInstall

angular2-api

Package Overview
Dependencies
7
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    angular2-api

Api service for angular to work with REST resources


Version published
Weekly downloads
9
increased by350%
Maintainers
1
Install size
61.8 kB
Created
Weekly downloads
 

Readme

Source

angular2-api

Api service for angular2 to work with REST resources

Getting Started

$ npm i --save angular2-api

Add this to you're bootstrap file

import {ApiService, provideApiService} from 'angular2-api'

bootstrap(App, [
  ApiService
])

// To provide custom global deserialize/serialize/serializeParams
bootstrap(App, [
  provide(ApiConfig, {useValue: new ApiConfig({
    basePath: '/test',

    deserialize(data) {
      return data
    },

    serialize(data) {
      return data
    },

    serializeParams(data) {
      return data
    }
  })}),
  ApiService
])

Using ApiService

The most common use case for api service would be to create resources

import {Injectable} from 'angular2/core'
import {ApiResource, ApiService} from 'angular2-api'

@Injectable()
export class MyResource implements ApiResource {
  endpoint: string = 'my-endpoint'
  idAttribute: string = 'testId' // If not provided will use 'id'

  deserialize(data) {
    return data
  }

  serialize(data) {
    return data
  }
  
  serializeParams(params) {
    return params
  }
}

export class MyComponent {
  constructor(apiService: ApiService, myResource: MyResource) {
    apiService.find(myResource, 1, ...args)
  }
}

Methods

For url you can pass an array of strings or a string

  • ApiService.get(resource, url, [params])
  • ApiService.put(resource, url, data, [params])
  • ApiService.patch(resource, url, data, [params])
  • ApiService.post(resource, url, data, [params])
  • ApiService.delete(resource, url, [params])
  • ApiService.find(resource, id, [params])
  • ApiService.findAll(resource, [params])
  • ApiService.create(resource, data, [params])
  • ApiService.update(resource, [data, params])
  • ApiService.destroy(resource, [id, params])

Keywords

FAQs

Last updated on 14 May 2016

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc