0

So I know that there are different node packages that I could use like request and like even the standard HTTP and HTTPS ones but I do not see how I can pass in route parameters within my requests like I can with Postman.

I got this so far but I do not know where to put my route parameters.

1
  • Welcome to Stackoverflow. Please do not post code as image. Here is a question about it. Please check the answers to a better experience when asking. meta.stackoverflow.com/questions/285551/… Commented May 18, 2020 at 15:15

2 Answers 2

0

I'm not sure that I got your question right. You know that there are packages but you do not want to use them?

anyway, here there is a similar question that you might find useful (if I got your problem right ) node.js http set request parameters

to send the request parameters you can choose to put them in your path by doing:

const options = {
    hostname: "localhost", 
    port: 3000, 
    method: "POST", 
    path:"/add?yourParameter=yourParameterValue", 
    headers: {}
}

but it is hard coded, so it is not a good way to do it.. You can also think of string literal, here the documentation https://developers.google.com/web/updates/2015/01/ES6-Template-Strings

Sign up to request clarification or add additional context in comments.

Comments

0

You should pass in your parameter by including it in your path.

//define your route params as string here
const routeParam = ''
const options = {
  /////// your properties
  path: /add/${routeParam}
}

And all route params are passed as string variable. So please make sure parsing it from the server side in case your route param is int.

parseInt(passedParam);

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.