Skip to content

Latest commit

 

History

History

http-request

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Request

Simple HTTP client.

Installation

$ npm install @podium/test-utils --save-dev

Getting started

Do a GET:

const result = await request({
    address: 'http://localhost:8080',
    pathname: '/foo'
});

console.log(result);

API

request(options, payload)

Do a HTTP request.

const result = await request({
    address: 'http://localhost:8080',
    pathname: '/foo'
});

Return an promise which resolves with and object with the http headers and response body:

{
    headers: {
        'max-age': '60000',
    },
    body: '<div>some content</div>'
}

options

option type default description
address string Address to the http server
pathname string The pathname to request
method string GET What method the request is
json boolean false If the body response should be parsed from json to a object

payload

If the option method is POST or PUT the payload to send to the server. The payload should be a string.

const result = await request({
    address: 'http://localhost:8080',
    pathname: '/foo',
    method: 'POST',
}, 'Payload as a string');

console.log(result);