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

Fetcher

Extends:

PathFetcher → Fetcher

Performs REST requests to constant url.

Example:

import {Fetcher} from 'fetchers';

const fetcher = new Fetcher('http://example.com', {credentials: 'include'});

fetcher.get()
   .then(response => response.ok ? response.json() : response.statusText)
   .then(data => console.log(data));

Constructor Summary

Public Constructor
public

constructor(url: String, defaultOptions: RequestOptions, handlers: Handlers)

Method Summary

Public Methods
public

async delete(body: *, options: RequestOptions): Promise<Response>

Performs DELETE request.

public

async get(options: RequestOptions): Promise<Response>

Performs GET request.

public

async head(body: *, options: RequestOptions): Promise<Response>

Performs HEAD request.

public

async patch(body: *, options: RequestOptions): Promise<Response>

Performs PATCH request.

public

async post(body: *, options: RequestOptions): Promise<Response>

Performs POST request.

public

async put(body: *, options: RequestOptions): Promise<Response>

Performs PUT request.

Inherited Summary

From class PathFetcher
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(url: String, defaultOptions: RequestOptions, handlers: Handlers) source

Override:

PathFetcher#constructor

Params:

NameTypeAttributeDescription
url String

url used for every request

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(body: *, options: RequestOptions): Promise<Response> source

Performs DELETE request.

Override:

PathFetcher#delete

Params:

NameTypeAttributeDescription
body *
  • optional

request body

options RequestOptions
  • optional

custom options

Return:

Promise<Response>

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

Performs GET request.

Override:

PathFetcher#get

Params:

NameTypeAttributeDescription
options RequestOptions
  • optional

custom options

Return:

Promise<Response>

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

Performs HEAD request.

Override:

PathFetcher#head

Params:

NameTypeAttributeDescription
body *
  • optional

request body

options RequestOptions
  • optional

custom options

Return:

Promise<Response>

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

Performs PATCH request.

Override:

PathFetcher#patch

Params:

NameTypeAttributeDescription
body *
  • optional

request body

options RequestOptions
  • optional

custom options

Return:

Promise<Response>

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

Performs POST request.

Override:

PathFetcher#post

Params:

NameTypeAttributeDescription
body *
  • optional

request body

options RequestOptions
  • optional

custom options

Return:

Promise<Response>

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

Performs PUT request.

Override:

PathFetcher#put

Params:

NameTypeAttributeDescription
body *
  • optional

request body

options RequestOptions
  • optional

custom options

Return:

Promise<Response>