3.2.4 • Published 2 years ago

@covalent/http v3.2.4

Weekly downloads
955
License
MIT
Repository
github
Last release
2 years ago

RESTService

Abstract class provided with methods that wraps http services to facilitate REST API calls.

API Summary

Methods

  • query: function(query?: IRestQuery, transform?: IRestTransform)
    • Creates a GET request to the generated endpoint URL.
  • get: function(id: string | number, transform?: IRestTransform)
    • Creates a GET request to the generated endpoint URL, adding the ID at the end.
  • create: function(obj: T, transform?: IRestTransform)
    • Creates a POST request to the generated endpoint URL.
  • update: function(id: string | number, obj: T, transform?: IRestTransform)
    • Creates a PATCH request to the generated endpoint URL, adding the ID at the end.
  • delete: function(id: string | number, transform?: IRestTransform)
    • Creates a DELETE request to the generated endpoint URL, adding the ID at the end.
  • buildUrl: function(id?: string | number, query?: IRestQuery)
    • Builds the endpoint URL with the configured properties and arguments passed in the method.

Usage

Example:

import { Injectable } from '@angular/core';
import { Response, Http, Headers } from '@angular/http';
import { RESTService, HttpInterceptorService } from '@covalent/http';

@Injectable()
export class CustomRESTService extends RESTService<any> {

  constructor(private _http: Http /* or HttpInterceptorService */) {
    super(_http, {
      baseUrl: 'www.api.com',
      path: '/path/to/endpoint',
      headers: new Headers(),
      dynamicHeaders: () => new Headers(),
      transform: (res: Response): any => res.json(),
    });
  }
}

Note: the constructor takes any object that implements the methods in IHttp interface. This can be the @angular Http service, the covalent HttpInterceptorService or a custom service.

export interface IHttp {
  delete: (url: string, options?: RequestOptionsArgs) => Observable<Response>;
  get: (url: string, options?: RequestOptionsArgs) => Observable<Response>;
  head: (url: string, options?: RequestOptionsArgs) => Observable<Response>;
  patch: (url: string, body: any, options?: RequestOptionsArgs) => Observable<Response>;
  post: (url: string, body: any, options?: RequestOptionsArgs) => Observable<Response>;
  put: (url: string, body: any, options?: RequestOptionsArgs) => Observable<Response>;
  request: (url: string | Request, options: RequestOptionsArgs) => Observable<Response>;
}
3.2.2

2 years ago

3.2.1

2 years ago

3.2.0

2 years ago

3.2.4

2 years ago

3.2.3

2 years ago

3.1.2-beta.7

2 years ago

3.1.2

2 years ago

3.1.2-beta.6

2 years ago

3.1.2-beta.4

3 years ago

3.1.1

3 years ago

3.1.1-beta.1

3 years ago

3.1.0

4 years ago

3.1.0-beta.2

4 years ago

3.0.1

4 years ago

3.1.0-beta.1

4 years ago

3.0.0

4 years ago

3.0.0-rc.2

4 years ago

3.0.0-rc.1

4 years ago

3.0.0-beta.3

4 years ago

3.0.0-beta.2

4 years ago

3.0.0-beta.1-2

5 years ago

3.0.0-beta.1-1

5 years ago

3.0.0-beta.1

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

2.0.0-rc.2

5 years ago

2.0.0-rc.1

5 years ago

2.0.0-beta.5

5 years ago

2.0.0-beta.4

5 years ago

2.0.0-beta.3

6 years ago

2.0.0-beta.2

6 years ago

1.0.1

6 years ago

2.0.0-beta.1

6 years ago

1.0.0

6 years ago

1.0.0-rc.5

6 years ago

1.0.0-rc.4

6 years ago

1.0.0-rc.3

6 years ago

1.0.0-rc.2

6 years ago

1.0.0-rc.1

6 years ago

1.0.0-rc.0

6 years ago

1.0.0-beta.8-1

7 years ago

1.0.0-beta.8

7 years ago

1.0.0-beta.7

7 years ago

1.0.0-beta.6

7 years ago

1.0.0-beta.5-1

7 years ago

1.0.0-beta.5

7 years ago

1.0.0-beta.4

7 years ago

1.0.0-beta.3-2

7 years ago

1.0.0-beta.3-1

7 years ago

1.0.0-beta.3

7 years ago

1.0.0-beta.2-1

7 years ago

1.0.0-beta.2

7 years ago

1.0.0-beta.1-1

7 years ago

1.0.0-beta.1

7 years ago

0.10.2

7 years ago

0.10.1

7 years ago

0.10.0

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.8.1

8 years ago

0.8.0

8 years ago

0.7.0

8 years ago

0.6.0-exp1

8 years ago

0.6.0

8 years ago