MilkScript

Automate tasks with MilkScript.

menu

FetchOptions

The options that can be applied to a fetch request.


body

The body for the request. It can be a string or a JavaScript object. A JavaScript object is interpreted as a map of form field names to values, where the values are strings.

Note that a request using the GET or HEAD method cannot have a body.

Example

// Makes a POST request with form data.
const response = fetch('https://httpbin.org/post', {
  method: 'POST',
  body: {
    name: 'Bob T. Monkey',
    email: 'bob@rememberthemilk.com'
  }
});
console.log(response.getContentText());

headers

A JavaScript key/value map of HTTP headers for the request.

Example

// Makes a GET request with a custom header.
const response = fetch('https://httpbin.org/headers', {
  headers: { 'x-my-custom-header': 'MilkScript custom header' },
});
console.log(response.getContentText());

method

The request method, e.g., GET, POST. Defaults to GET if not specified.

Example

// Makes a POST request with a JSON body.
const response = fetch('https://httpbin.org/post', {
  method: 'POST',
  body: JSON.stringify({
    name: 'Bob T. Monkey',
    email: 'bob@rememberthemilk.com'
  })
});
console.log(response.getContentText());