Skip to content
Pavel Koch edited this page Mar 2, 2019 · 7 revisions

Interface Client

import { Client } from 'awi'

This is the interface implemented by the Awi class.


use (interceptor: Interceptor, priority?: number) : Client

Provides a way to intercept any request directly. The callback takes in an instance of Request and alters its contents. The return value is disregarded.

Parameters

  • interceptor: Interceptor - The function that alters the event
  • priority?: number - The priority of the interceptor, interceptors with higher priority are executed first

Returns

Client - The instance for chaining


send<T extends Response> () : Promise<T>

Perform the transformed request.

Type Parameters

  • T extends Response - The desired response type

Returns

Promise<T> - The desired response

Throws

  • HttpException - If something goes wrong when executing the request

get<T extends Response> (path?: string) : Promise<T>

delete<T extends Response> (path?: string) : Promise<T>

head<T extends Response> (path?: string) : Promise<T>

options<T extends Response> (path?: string) : Promise<T>

Get, delete, head and options request execution shorthands.

Parameters

  • path?: string - The path to use for the request

Type Parameters

  • T extends Response - The desired response type

Returns

Promise<T> - The desired response

Throws

  • HttpException - If something goes wrong when executing the request

post<T extends Response> (path?: string, body?: any) : Promise<T>

put<T extends Response> (path?: string, body?: any) : Promise<T>

patch<T extends Response> (path?: string, body?: any) : Promise<T>

Post, put and patch request execution shorthands.

Parameters

  • path?: string - The path to use for the request
  • body?: any - he body to be sent with the request

Type Parameters

  • T extends Response - The desired response type

Returns

Promise<T> - The desired response

Throws

  • HttpException - If something goes wrong when executing the request

body<T> (path?: string) : Promise<T>

A request helper that only returns the body of the response.

Parameters

  • path?: string - The path to use for the request

Type Parameters

  • T - The desired response body type

Returns

Promise<T> - The desired response

Throws

  • HttpException - If something goes wrong when executing the request

optional<T> (path?: string) : Promise<Optional<T>>

A request helper that only returns the body of the response and instead of rejecting the promise, it resolves an Optional<T>.

Parameters

  • path?: string - The path to use for the request

Type Parameters

  • T - The desired response body type

Returns

Promise<Optional<T>> - The desired response wrapped in an optional

Throws

  • HttpException - If something goes wrong when executing the request

--

Clone this wiki locally