0

I need to make a http call within my node server .The optional parameter is:

  • 'name='

This means that url (relative path) should look like:

/v1/clans?name=**exampleValue**

So far the options for my http request looks like:

app.get('/v1/:clans?=:name', (req, res) => {
    console.log(req.path)
    const options = {
        host: 'api.clashofclans.com',
        path: req.path,
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            Authorization: 'Bearer *token*'
        }
    };
    const x = https.get(options, (request) => {...});

But that doesnt work out. Does someone know how to include the optional parameters in my path property?

1 Answer 1

4

You don't. That's not a parameter you're thinking of. That's a query parameter and your path should look like this:

'/v1/clans

You retrieve the query parameter using req.query.<parameter> in your case req.query.name

The optional url parameter you're thinking of would be like this /v1/clans/:name and would be accessible using req.params.name.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.