Simple HTTP client.
$ npm install @podium/test-utils --save-dev
Do a GET:
const result = await request({
address: 'http://localhost:8080',
pathname: '/foo'
});
console.log(result);
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>'
}
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 |
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);