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

HttpService

Extends:

IHttpServiceAbstractHttpService → HttpService

Indirect Implements:

Class for making HTTP calls with the got library.

Test:

Method Summary

Public Methods
public

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

Request to download an item.

public

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

Make a HTTP 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.

From class AbstractHttpService
public

The base url of the website to scrape.

public

The default options for the HTTP requests.

private

The debug function for extra output.

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.

Public Methods

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

Request to download an item.

Override:

IHttpService#download

Params:

NameTypeAttributeDescription
endpoint string
  • nullable: false

The uri to the item.

filePath string
  • nullable: false

The name of the file to save the item.

Return:

Promise<string, Error>

Message when it's finally downloaded.

Test:

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

Make a HTTP request.

Override:

IHttpService#request

Params:

NameTypeAttributeDescription
method string
  • nullable: false

The method of the HTTP request.

endpoint string
  • optional
  • nullable: false

The endpoint to make the HTTP request to.

opts Object
  • optional
  • nullable: true

The options for the HTTP request.

raw boolean
  • optional
  • nullable: true

Return the raw body.

Return:

Promise<Object, Error>

Promise with the HTML loaded in cheerio.

Test: