Here's a step by step for this example:
async request(url[, body=null, headers={}])
- The
async means it's an async function that always returns a promise.
url is the first argument and is required.
- The
[, args here ] means that the arguments inside the brackets are optional.
- The comma in
[, args here] means that if you include these arguments, then a comma is required to separate each argument from the previous one.
body=null means that if you don't pass the body argument, the default value is null
headers={} means that if you don't pass the headers argument, the default value is an empty object.
So, you can call it like any of these:
request(myUrl).then(...).catch(...)
request(myUrl, myBody).then(...).catch(...)
request(myUrl, myBody, myHeaders).then(...).catch(...)