Home Reference Source
import PathFetcher from 'fetchers/src/path-fetcher.js'
public class | source

PathFetcher

Direct Subclass:

Fetcher

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:

NameTypeAttributeDescription
baseUrl String
  • optional
  • default: ''
defaultOptions RequestOptions
  • optional
  • default: {}

default options used for every request

handlers Handlers
  • optional
  • default: {}

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:

NameTypeAttributeDescription
path String
  • optional

path added to base url

body *
  • optional

request body

options RequestOptions
  • optional

custom options

Return:

Promise<Response>

public async get(path: String, options: RequestOptions): Promise<Response> source

Performs GET request to url path.

Params:

NameTypeAttributeDescription
path String
  • optional

path added to base url

options RequestOptions
  • optional

custom options

Return:

Promise<Response>

public async head(path: String, body: *, options: RequestOptions): Promise<Response> source

Performs HEAD request to url path.

Params:

NameTypeAttributeDescription
path String
  • optional

path added to base url

body *
  • optional

request body

options RequestOptions
  • optional

custom options

Return:

Promise<Response>

public async patch(path: String, body: *, options: RequestOptions): Promise<Response> source

Performs PATCH request to url path.

Params:

NameTypeAttributeDescription
path String
  • optional

path added to base url

body *
  • optional

request body

options RequestOptions
  • optional

custom options

Return:

Promise<Response>

public async post(path: String, body: *, options: RequestOptions): Promise<Response> source

Performs POST request to url path.

Params:

NameTypeAttributeDescription
path String
  • optional

path added to base url

body *
  • optional

request body

options RequestOptions
  • optional

custom options

Return:

Promise<Response>

public async put(path: String, body: *, options: RequestOptions): Promise<Response> source

Performs PUT request to url path.

Params:

NameTypeAttributeDescription
path String
  • optional

path added to base url

body *
  • optional

request body

options RequestOptions
  • optional

custom options

Return:

Promise<Response>