Make HTTP requests
Maestro comes with its own JavaScript HTTP API
JSON
Use json()
function to parse JSON responses.
For example, assume that https://example.com/jsonEndpoint
returns the following result:
mySubField
could then be accessed in the following way:
POST request
To send body to a given endpoint, specify a body
parameter:
Setting a 'Content-Type'
header might be required. See Headers.
You can also send multipart form data by specyfying multipartForm
parameter:
In multipartForm
you can include many fields. It is also possible to upload multiple files in one request by using objects with filePath property. filePath
is required for the files. mediaType
is optional.
âšī¸ Note If you include both
body
andmultipartForm
in one request thenbody
will be ignored.
Headers
Headers can be provided in a headers
parameter
Other request types
The following request methods are provided out of the box:
http.get
http.post
http.put
http.delete
To send a request of any other HTTP method, use http.request
Response object
ok
true
if request was successful, false
otherwise
status
HTTP status code (i.e. 200
)
body
String body of the response
headers
response HTTP headers, where each header value is a string (or a comma-separated string in case of multiple values)
Example
Here's an example of using these utilities to perform a common test action, creating a user and populating it with data.
Shared Functions
The output object in JavaScript can hold functions as well as values and JSON objects. You can use this to put all of your bespoke API calls into the output object, and call them from elsewhere in your flow.
api.js:
flow.yaml:
Additional Information
For test developers looking for additional information on the API, and the structure of objects, the Maestro implementation is a wrapper around okhttp3.
Last updated
Was this helpful?