0.0.10 • Published 5 years ago

ng-aqueduct v0.0.10

Weekly downloads
13
License
-
Repository
-
Last release
5 years ago

NgAqueduct library

npm.io

Provides connection between Angular (7+) and Laravel (Laravel Helpers)

Installation

npm i ng-aqueduct --save

Set config and add NgAqueductModule into AppModule.

const environmentConfig = {
  url: 'https://api.site.com',
  domains: ['api.site.com']
};

@NgModule({
  ...
  imports: [
    ...
    NgAqueductModule.forRoot(environmentConfig),
    ...
  ],
})

How to use

If you are planning to use Aqueduct into service just extends service from the ApiService

import { ApiService, RequestTypes } from 'ng-aqueduct';

@Injectable({
  providedIn: 'root'
})
export class MyService extends ApiService<MyInterface> {

}

Note! An interface MyInterface must contains id field or extends from the ApiEntity interface. It neccessary for working with update/get methods.

Now you can use all CRUD methods. Read detailed information in documentation about requests and responses.

export class MyComponent {
 constructor(
    private myService: MyService,
  ) { }


  addAction(data: MyInterface) {
    this.myService
      .add(data)
      .then(response => {
        ...
      });
  }

  getAction(id: string | number) {
    this.myService
      .get(id)
      .then(response => {
        ...
      });
  }

  updateAction(id: number, status: bool) {
    const data = {
        id: id,
        status: status
    };

    this.myService
      .update(data)
      .then(response => {
        ...
      });
  }

  anotherUpdateAction(data: MyInterface) {
    this.myService
      .update(data)
      .then(response => {
        ...
      });
  }

  deleteAction(id: string | number) {
    this.myService
      .delete(id)
      .then(response => {
        ...
      });
  }
}