npm.io
1.5.3 • Published 5 years ago

@funxtion/ng-funxtion-api-client

Licence
Version
1.5.3
Deps
1
Size
2.6 MB
Vulns
0
Weekly
0

Funxtion API Client for Angular

This is an Angular library for communication with the Funxtion API v2.

Installation

npm i @funxtion/ng-funxtion-api-client

Dependencies

OAuth 2

Manfred Steyer's Angular OAuth 2

npm i angular-oauth2-oidc

This service can be accessed through FunxtionApiClientService.oauth.

JSON API

Ghidoz' Angular 2 JSON API

npm i angular2-jsonapi

This service can be accessed through FunxtionApiClientService.datastore.

Refreshing of tokens happens automatically in the OauthService for logged in users. This service also passes the tokens to the DatastoreService.

Environment

Implement the EnvironmentVariables interface on your environment file. Do this for both your local and production environment files.

Usage

AppModule
import { NgModule } from '@angular/core';
import { FunxtionApiClientModule, FunxtionApiClientService } from '@funxtion/ng-funxtion-api-client';

@NgModule({
    imports: [FunxtionApiClientModule],
    providers: [FunxtionApiClientService]
})
export class AppModule {}
AppComponent
import { FunxtionApiClientService } from '@funxtion/ng-funxtion-api-client';
import { environment } from '../environments/environment';

export class AppComponent {
    constructor(private funxtion: FunxtionApiClientService) {
        this.funxtion.setup(environment).then(() => {
            // optionally listen for API errors
            this.funxtion.datastore.error$.subscribe((error) => {
                // handle the error(s)
            });

            // other logic for the app
        });
    }
}
Services

In addition to the third party services mentioned in the dependencies section, the library contains the following custom services:

UserService

Use this service for managing user actions.

Properties

  • data (User model)
  • password (can be used for form model binding, gets erased after login and register)

Methods

  • login
  • logout
  • register
  • getUser
ClientService

Use this service for managing client actions.

Properties

  • data (Client model)

Methods

  • getClient