PathFetcher
Direct Subclass:
Performs REST requests to constant base url with different relative paths.
Example:
import {PathFetcher} from 'fetchers';
const fetcher = new PathFetcher('http://example.com', {credentials: 'include'});
fetcher.get('/get')
.then(response => response.ok ? response.json() : response.statusText)
.then(data => console.log(data));
fetcher.post('/post', JSON.stringify({foo: 'bar'}))
.then(response => response.ok ? response.json() : response.statusText)
.then(data => console.log(data));
Constructor Summary
Public Constructor | ||
public |
constructor(baseUrl: String, defaultOptions: RequestOptions, handlers: Handlers) |
Method Summary
Public Methods | ||
public |
async delete(path: String, body: *, options: RequestOptions): Promise<Response> Performs DELETE request to url path. |
|
public |
async get(path: String, options: RequestOptions): Promise<Response> Performs GET request to url path. |
|
public |
async head(path: String, body: *, options: RequestOptions): Promise<Response> Performs HEAD request to url path. |
|
public |
async patch(path: String, body: *, options: RequestOptions): Promise<Response> Performs PATCH request to url path. |
|
public |
async post(path: String, body: *, options: RequestOptions): Promise<Response> Performs POST request to url path. |
|
public |
async put(path: String, body: *, options: RequestOptions): Promise<Response> Performs PUT request to url path. |
Public Constructors
public constructor(baseUrl: String, defaultOptions: RequestOptions, handlers: Handlers) source
Params:
Name | Type | Attribute | Description |
baseUrl | String |
|
|
defaultOptions | RequestOptions |
|
default options used for every request |
handlers | Handlers |
|
functions for processing every request and response |
Public Methods
public async delete(path: String, body: *, options: RequestOptions): Promise<Response> source
Performs DELETE request to url path.
Params:
Name | Type | Attribute | Description |
path | String |
|
path added to base url |
body | * |
|
request body |
options | RequestOptions |
|
custom options |
public async get(path: String, options: RequestOptions): Promise<Response> source
Performs GET request to url path.
Params:
Name | Type | Attribute | Description |
path | String |
|
path added to base url |
options | RequestOptions |
|
custom options |
public async head(path: String, body: *, options: RequestOptions): Promise<Response> source
Performs HEAD request to url path.
Params:
Name | Type | Attribute | Description |
path | String |
|
path added to base url |
body | * |
|
request body |
options | RequestOptions |
|
custom options |
public async patch(path: String, body: *, options: RequestOptions): Promise<Response> source
Performs PATCH request to url path.
Params:
Name | Type | Attribute | Description |
path | String |
|
path added to base url |
body | * |
|
request body |
options | RequestOptions |
|
custom options |
public async post(path: String, body: *, options: RequestOptions): Promise<Response> source
Performs POST request to url path.
Params:
Name | Type | Attribute | Description |
path | String |
|
path added to base url |
body | * |
|
request body |
options | RequestOptions |
|
custom options |
public async put(path: String, body: *, options: RequestOptions): Promise<Response> source
Performs PUT request to url path.
Params:
Name | Type | Attribute | Description |
path | String |
|
path added to base url |
body | * |
|
request body |
options | RequestOptions |
|
custom options |