Makes an HTTP request and returns the response. Give an absolute HTTP(S) URL or a path such as '/api/notes' to call the project's own routes in this process.
Parameter
Takes
urlrequired
string. The absolute URL or project route to request.
optionsoptional
map. Configure this request with the fields below.
postoptional
any. Sends this body with POST: @api('/notes', post: { title: 'Ship it' }). Maps and lists are sent as JSON, base64 values as binary data, and other values as UTF-8 text. Without post:, put:, patch: or delete:, the request is a GET.
putoptional
any. Sends this body with PUT.
patchoptional
any. Sends this body with PATCH.
deleteoptional
any. Sends a DELETE. delete: true sends no body; anything else is sent as the body.
beareroptional
string. An Authorization: Bearer header with this token.
type. Checks the response succeeded and reads its JSON as this type. @api($url, as: Note) is @api($url)->check()->convert(from: json, as: Note).
encodingoptional
one of these words: 'json'|form|multipart. How a map body is sent: json (the default), form (application/x-www-form-urlencoded, as an HTML form or an OAuth token endpoint expects) or multipart (multipart/form-data, where base64 values and uploaded files become file parts).
queryoptional
map. Values added to the URL's query string: query: { page: 2, tag: ['a', 'b'] }. A list is sent once per item.
Downloads a URL to a file and returns the file's full path. Folders are created as needed, and a relative path is from the script's folder. overwrite: false keeps a file that is already there.
Parameter
Takes
urlrequired
any value
torequired
any value
overwriteoptional
a flag: overwrite or not overwrite
Arguments can be named: @download(…, to: …, overwrite: …).