MilkScript

Automate tasks with MilkScript.

menu

FetchResponse

Represents the response to a fetch request.


getContentFile()

Gets the response body as a File.

Return value

File

Example

// Makes a GET request and logs the file name.
const response = fetch('https://httpbin.org/response-headers?Content-Disposition=attachment;%20filename%3d%22test.json%22');
console.log(response.getContentFile().getName());

getContentText()

Gets the text representation of the response body.

Return value

string

Example

// Makes a GET request and logs the returned content.
const response = fetch('https://httpbin.org/json');
console.log(response.getContentText());

getHeaders()

Gets the headers object associated with the response.

Return value

The keys of the returned object are the header names and the values are the respective header values.

Example

// Makes a GET request and logs the response headers.
const response = fetch('https://httpbin.org/get');
console.log(JSON.stringify(response.getHeaders()));

getResponseCode()

Gets the status code of the response. (This will be 200 for a success).

Return value

number

Example

// Makes a GET request and logs the response status code.
const response = fetch('https://httpbin.org/status/418');
console.log(`Response status code: ${response.getResponseCode()}`);