Skip to content

Latest commit

 

History

History
98 lines (74 loc) · 2.73 KB

README.md

File metadata and controls

98 lines (74 loc) · 2.73 KB

npm npm npm

pigeon

Pigeon Restful Provider

HTTP Service Provider for Ionic: Our skillful mail pigeon will help you carry out REST requests. Our Pigeon is a RESTful Provider.

Install

npm install @ioniczoo/pigeon-restful-provider --save

Import HttpClientModule and 'RestfulProvider' to app.module.ts

import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';

import { HttpClientModule } from '@angular/common/http';
import { RestfulProvider } from '@ioniczoo/pigeon-restful-provider';

import { MyApp } from './app.component';

@NgModule({
  declarations: [
    MyApp
  ],
  imports: [
    HttpClientModule,
    IonicModule.forRoot(MyApp, {
      pigeon_debug: true, // Enable Debug
      pigeon_loader: true, // Enable Loading
      pigeon_alert: true, // Enable Error Alert
      pigeon_host: 'https://randomuser.me', // Add Host
      pigeon_status: { // Add Custom Message
        404: ['Ops', '404 - Not found']
      }
    })
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp
  ],
  providers: [
    RestfulProvider,
    { provide: ErrorHandler, useClass: IonicErrorHandler }
  ]
})
export class AppModule {}

Example

...
import { RestfulProvider } from '@ioniczoo/pigeon-restful-provider';

@IonicPage()
@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
})
export class HomePage {

  constructor(private restful: RestfulProvider) {

    /**
    * @param  {string}      method  http    method
    * @param  {string}      url     server  url
    * @param  {any}         body    request body
    * @param  {HttpParams}  params  request params
    * @param  {HttpHeaders} headers request headers
    */
    this.restful.request('get', '/api/?results=10')
      .then((data) => { console.log(data); })
      .catch((data) => { console.log(data); });
  }
}

Author

André Argôlo

Contribute

Create issues and request pull-request.

License

GNU General Public License v3.0