Manual Reference Source Test
import AbstractHttpService from 'pop-api-scraper/src/http/AbstractHttpService.js'
public class | source

AbstractHttpService

Extends:

IHttpService → AbstractHttpService

Direct Subclass:

HttpService

Implements:

Class for making HTTP calls.

Test:

Constructor Summary

Public Constructor
public

constructor(baseUrl: string, options: Object)

Create a new Request object.

Member Summary

Public Members
public

The base url of the website to scrape.

public

The default options for the HTTP requests.

Private Members
private

The debug function for extra output.

Method Summary

Public Methods
public

delete(endpoint: string, opts: Object): Promise<Object, Error>

Make a DELETE request.

public

get(endpoint: string, opts: Object, raw: boolean): Promise<Object, Error>

Make a GET request.

public

Handle the body response string.

public

post(endpoint: string, opts: Object): Promise<Object, Error>

Make a POST request.

public

printDebug(method: string, uri: string, opts: Object): undefined

Print the debug message.

public

put(endpoint: string, opts: Object): Promise<Object, Error>

Make a PUT request.

Inherited Summary

From class IHttpService
public

delete(endpoint: string, opts: Object): Promise<Object, Error>

Make a DELETE request.

public

download(endpoint: string, filePath: string): Promise<string, Error>

Request to download an item.

public

get(endpoint: string, opts: Object, raw: boolean): Promise<Object, Error>

Make a GET request.

public

post(endpoint: string, opts: Object): Promise<Object, Error>

Make a POST request.

public

printDebug(method: string, uri: string, opts: Object): undefined

Print the debug message.

public

put(endpoint: string, opts: Object): Promise<Object, Error>

Make a PUT request.

public

request(method: string, endpoint: string, opts: Object, raw: boolean): Promise<Object, Error>

Make a HTTP request.

Public Constructors

public constructor(baseUrl: string, options: Object) source

Create a new Request object.

Params:

NameTypeAttributeDescription
baseUrl string
  • nullable: false

The base url of the website to scrape.

options Object
  • default: {}
  • nullable: true

The default options for the HTTP requests.

Test:

Public Members

public baseUrl: string source

The base url of the website to scrape.

public options: Object source

The default options for the HTTP requests.

Private Members

private _debug: Function source

The debug function for extra output.

Public Methods

public delete(endpoint: string, opts: Object): Promise<Object, Error> source

Make a DELETE request.

Override:

IHttpService#delete

Params:

NameTypeAttributeDescription
endpoint string
  • optional
  • nullable: false

The endpoint to make the DELETE request to.

opts Object
  • optional
  • default: {}
  • nullable: true

The options for the HTTP DELETE request.

Return:

Promise<Object, Error>

Promise with the HTML loaded in cheerio.

Test:

public get(endpoint: string, opts: Object, raw: boolean): Promise<Object, Error> source

Make a GET request.

Override:

IHttpService#get

Params:

NameTypeAttributeDescription
endpoint string
  • optional
  • default: ''
  • nullable: false

The endpoint to make the GET request to.

opts Object
  • optional
  • default: {}
  • nullable: true

The options for the HTTP GET request.

raw boolean
  • optional
  • default: false
  • nullable: true

Return json object.

Return:

Promise<Object, Error>

Promise with the HTML loaded in cheerio.

Test:

public handleBody(body: string, raw: boolean): Function | string source

Handle the body response string.

Params:

NameTypeAttributeDescription
body string
  • nullable: false

The body to parse.

raw boolean
  • nullable: true

Return the raw body.

Return:

Function | string

The raw body or the body parsed by cheerio.

Test:

public post(endpoint: string, opts: Object): Promise<Object, Error> source

Make a POST request.

Override:

IHttpService#post

Params:

NameTypeAttributeDescription
endpoint string
  • optional
  • nullable: false

The endpoint to make the POST request to.

opts Object
  • optional
  • default: {}
  • nullable: true

The options for the HTTP POST request.

Return:

Promise<Object, Error>

Promise with the HTML loaded in cheerio.

Test:

public printDebug(method: string, uri: string, opts: Object): undefined source

Print the debug message.

Override:

IHttpService#printDebug

Params:

NameTypeAttributeDescription
method string
  • nullable: false

The method of the HTTP request.

uri string
  • nullable: false

The uri of the HTTP request.

opts Object
  • default: this._opts
  • nullable: true

The options for the HTTP request.

Return:

undefined

Test:

public put(endpoint: string, opts: Object): Promise<Object, Error> source

Make a PUT request.

Override:

IHttpService#put

Params:

NameTypeAttributeDescription
endpoint string
  • optional
  • nullable: false

The endpoint to make the PUT request to.

opts Object
  • optional
  • default: {}
  • nullable: true

The options for the HTTP PUT request.

Return:

Promise<Object, Error>

Promise with the HTML loaded in cheerio.

Test: