aft-web-services
Version:
Automated Functional Testing (AFT) module for testing web services over HTTP and HTTPS
123 lines (122 loc) • 4.11 kB
TypeScript
/// <reference types="node" />
import { HttpMethod, HttpRequest, HttpResponse } from "./http-custom-types";
import { AftConfig } from 'aft-core';
import { OutgoingHttpHeaders } from 'http2';
export declare class HttpServiceConfig {
defaultUrl: string;
defaultHeaders: OutgoingHttpHeaders;
defaultMethod: HttpMethod;
defaultAllowRedirect: boolean;
defaultPostData: string;
defaultMultipart: boolean;
}
/**
* supports performing requests over http / https returning the response as a
* `HttpResponse` object. Requests should include a URL at a minimum,
* but may also specify additional details such as headers, auto redirect,
* post data and the request method (GET|POST|PUT|DELETE|UPDATE)
* ex:
* ```typescript
* await httpService.performRequest({url: 'https://some.domain/path'});
* ```
* or fully as:
* ```typescript
* await httpService.performRequest({
* url: 'https://some.domain/path',
* allowAutoRedirect: false,
* headers: {"Authorization": "basic AS0978FASLKLJA/=="},
* method: 'POST',
* postData: someObject,
* multipart: false
* });
* ```
* or multipart post as:
* ```typescript
* let formData = new FormData();
* formData.append("Authorization": "basic AS0978FASLKLJA/==");
* await httpService.performRequest({
* url: 'https://some.domain/path',
* allowAutoRedirect: false,
* method: 'POST',
* postData: formData,
* multipart: true
* });
* ```
*/
export declare class HttpService {
private readonly aftCfg;
constructor(aftCfg?: AftConfig);
/**
* issues a request over http / https and returns the response as a
* `HttpResponse` object. Requests should include a URL at a minimum,
* but may also specify additional details such as headers, auto redirect,
* post data and the request method (GET|POST|PUT|DELETE|UPDATE)
* ex:
* ```typescript
* await httpService.performRequest({url: 'https://some.domain/path'});
* ```
* or fully as:
* ```typescript
* await httpService.performRequest({
* url: 'https://some.domain/path',
* allowAutoRedirect: false,
* headers: {"Authorization": "basic AS0978FASLKLJA/=="},
* method: 'POST',
* postData: someObject,
* multipart: false
* });
* ```
* or multipart post as:
* ```typescript
* let formData = new FormData();
* formData.append("Authorization": "basic AS0978FASLKLJA/==");
* await httpService.performRequest({
* url: 'https://some.domain/path',
* allowAutoRedirect: false,
* method: 'POST',
* postData: formData,
* multipart: true
* });
* ```
* @param req a `HttpResponse` object that specifies details of the request
*/
performRequest(req?: HttpRequest): Promise<HttpResponse>;
private setRequestDefaults;
private _request;
private _response;
}
/**
* supports performing requests over http / https returning the response as a
* `HttpResponse` object. Requests should include a URL at a minimum,
* but may also specify additional details such as headers, auto redirect,
* post data and the request method (GET|POST|PUT|DELETE|UPDATE)
* ex:
* ```typescript
* await httpService.performRequest({url: 'https://some.domain/path'});
* ```
* or fully as:
* ```typescript
* await httpService.performRequest({
* url: 'https://some.domain/path',
* allowAutoRedirect: false,
* headers: {...HttpHeaders.Authorization.basic('myUser', 'myPass')},
* method: 'POST',
* postData: someObject,
* multipart: false
* });
* ```
* or multipart post as:
* ```typescript
* let formData = new FormData();
* formData.append('file', fs.createReadStream('/path/to/file.ext'));
* await httpService.performRequest({
* url: 'https://some.domain/path',
* allowAutoRedirect: false,
* headers: {...HttpHeaders.Authorization.basic('myUser', 'myPass')}
* method: 'POST',
* postData: formData,
* multipart: true
* });
* ```
*/
export declare const httpService: HttpService;