Q: Change parameters in HTTP web requests Hey Guys i'm very new to Web development. I used the fetch API to send a http request as shown below. It worked well. But now i want to change the second parameter(ie the IP address) when I execute a sql query. So the idea is to execute the sql query into the place where the IP is everytime i press a button in the webpage. Is it possible to set a variable for the sql query and write that variable in place of the IP? Any help is appreciated. Thanks
 fetch("    http://192.xx.x.xxx/abc-bin/output?username=one&password=xxxx&action=on&pin=relay")
  .then(function (response) {
    return response.json();
  })


A: Yes, this is a very common task in javascript. You have a number of options to solve this. How you set the variables will depend on your front-end javascript click handlers or html attributes on the buttons themselves.
Option 1 - String concatination
// Create a variable with the IP or Domain you would like to replace with
// If you didn't know domains are mapped to IPs, so you can use each inter-changably


// Example variables
const protocol = 'https://'
const domain = 'www.stackoverflow.com'
const path = '/abc-bin/output?username=one&password=xxxx&action=on&pin=relay'

// Concatinate to create single string
const url = protocol + domain + path

fetch(url)
  .then(function (response) {
    return response.json();
  })

Option 2 - String Interpolation
// Example variables
const domain = 'www.stackoverflow.com'

// Interpolate string...NOTE they aren't single quotes but 
// are backticks (top left key on US keyboard)
// You must wrap your variables with ${variableName} to
// have it interpreted as a string
const url = `https://${domain}/abc-bin/output?username=one&password=xxxx&action=on&pin=relay`

fetch(url)
  .then(function (response) {
    return response.json();
  })

