http

Provides methods for working with HTTP(S)

If you are using oxygen.conf.js, http module must be added.

modules: ['web', 'log', 'assert', 'date', 'db', 'email', 'eyes', 'http']

delete

Performs HTTP DELETE

Parameters:

Name

Type

Description

url

String

URL.

headers

Object

optional HTTP headers.

http.delete('https://jsonplaceholder.typicode.com/users/1')

get

Performs HTTP GET

Parameters:

Name

Type

Description

url

String

URL.

headers

Object

optional HTTP headers.

Returns:

Object - Either a parsed out JSON if Content-Type is application/json or a string.

var users = http.get(
'https://jsonplaceholder.typicode.com/users',
{ 'Content-Type': 'application/json' }
)
log.info(users[0])

getResponseHeaders

Returns response headers

Parameters:

Name

Type

Description

url

String

URL.

Returns:

Object - Response headers.

var url = 'https://jsonplaceholder.typicode.com'
var headers = http.getResponseHeaders(url)
log.info(headers)

post

Performs HTTP POST

Parameters:

Name

Type

Description

url

String

URL.

data

Object

Data.

headers

Object

optional HTTP headers.

Returns:

Object - Either a parsed out JSON if Content-Type is application/json or a string.

var url = 'https://jsonplaceholder.typicode.com'
var post = http.post(
url + '/users/1',
{ country: 'Switzerland' }
)
log.info(post)

put

Performs HTTP PUT

Parameters:

Name

Type

Description

url

String

URL.

data

Object

Data.

headers

Object

optional HTTP headers.

Returns:

Object - Either a parsed out JSON if Content-Type is application/json or a string.

var url = 'https://jsonplaceholder.typicode.com'
var put = http.put(
url + '/users/1',
{ username: "NewUsername" }
)
log.info(put)