What are the steps to send a https request in node js to a rest service?
I have an api exposed like (Original link not working…)
How to pass the request and what are the options I need to give for this API like
host, port, path and method?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The builtin
httpandhttpsmodules are perfectly good if a bit low-level. You’ll probably want to use a module that handles the details for you and provides a nice higher-level API.In node v18, node itself exposes a global
fetch(url)method, although as of 2023 it is still considered experimental and subject to change. Also, perhaps surprisingly, node’s builtinfetch()global does not use the HTTP stack provided by the traditional builtinhttp/httpsmodules.Instead, it uses a parallel, from-scratch HTTP stack rewrite called undici.
The builtin
fetch()is convenient, but given the instability and that it’s still missing a few features, I’d avoid it in production use until the feature is more stable.There are several popular modules available on npm.
requestused to be the very popular standard from the very early days of the node ecosystem, but it is no longer maintained, so you shouldn’t use it in new work.