This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

ng-requester
TypeScript icon, indicating that this package has built-in type declarations

0.7.12 • Public • Published

Angular Http Request Module

Usage:

npm install ng-requester --save

import { RequesterModule } from 'ng-requester';
 
@NgModule({
    imports: [
        ...
        RequesterModule
    ], ...
})
export class AppModule {}

Usage:

import { Requester, METHODS } from "ng-requester";
 
...
export class MyComponent {
    constructor(
        private req: Requester
    ) {
            req.set({
                    host: "http://host.com",
                    url: "api/endpoint",
                    method: METHODS.POST
                })
                .send()
                .toPromise(res => {
                    console.log(res);
                });
    }
}
import { Requester } from "ng-requester";
 
...
export class MyComponent {
    private baseRequest: Requester;
 
    constructor(
        private req: Requester
    ) {
        this.baseRequest = req
            .set({
                host: "http://host.com"
            });
    }
 
    private submit(data) {
        this.baseRequest.post("endpoint", {body: data}).toPromise().then(console.log);
    }
 
    private anOtherMethod() {
        this.baseRequest.get("anotherendpoint").toPromise().then(console.log);
    }
}

Authorization Example:

import { Requester, PreRequest } from "ng-requester";
 
    this.authorizedRequest = req
        .addOperator(
            new PreRequest(options => {
                    options.headers = options.headers.append("Authorization", "Bearer " + token);
                    return options;
            })
        );
    
    ...
 
    this.authorizedRequest.get("somesecretdataendpoint").toPromise().then(console.log);

Note:

All status codes do not throw error by default (404, 500) You have to define them as errors

import { Requester, PostRequest, Error } from "ng-requester";
 
    const SERVER_ERROR = Symbol("SERVER ERROR");
 
    this.request = req
        .addOperator(
            new PostRequest<any>(response => {
                if (response.data.status >= 500) {
                    throw new Error(SERVER_ERROR, response.data.body);
                }
                return response;
            })
        );
    
    ...
 
    this.request.get("somesecretdataendpoint").toPromise().then(console.log);

Readme

Keywords

Package Sidebar

Install

npm i ng-requester

Weekly Downloads

0

Version

0.7.12

License

ISC

Last publish

Collaborators

  • alisahinozcelik