I am trying to read the documentation at https://github.com/mikeal/bent.
I don't know how to read async request(url[, body=null, headers={}])
. Specifically, what does the ,
represent?
I have seen an answer to this question before, and I have searched for it, but I could not find it. Marking this as a duplicate of that would be fantastic.
Here's a step by step for this example:
async request(url[, body=null, headers={}])
async
means it's an async function that always returns a promise.url
is the first argument and is required.[, args here ]
means that the arguments inside the brackets are optional.[, 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(...)