2

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.

1

1 Answer 1

3

Here's a step by step for this example:

async request(url[, body=null, headers={}])
  1. The async means it's an async function that always returns a promise.
  2. url is the first argument and is required.
  3. The [, args here ] means that the arguments inside the brackets are optional.
  4. 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.
  5. body=null means that if you don't pass the body argument, the default value is null
  6. 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(...)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.