I first created a react app that was making API calls on client side, which is a big no no since it exposes the API key. So I have to create a backend express server to make API calls. However on client side, my react app allows you to type in a random username(which changes the state) in order to make an API call and get that users information. Is there a way to transfer state/ props from client side to backend express to complete an API call?
Here is the Express Code:
const express = require('express');
const app = express();
const fetch = require('node-fetch');
app.get('/api/customers', (req, res) => {
fetch('https://na1.api.riotgames.com/lol/summoner/v4/summoners/by-name/huhi?api_key=<MY_API_KEY>')
.then(res => res.json())
.then(result => res.json(result));
});
const port = 5000;
app.listen(port, () => console.log(`Server started on port ${port}`))
in this section
fetch('https://na1.api.riotgames.com/lol/summoner/v4/summoners/by-name/huhi?api_key=<MY_API_KEY>')
Is there a way to change the username after 'by-name/' to reginald, doublelift, faker, etc(stored in the client-side react state).
example
fetch('https://na1.api.riotgames.com/lol/summoner/v4/summoners/by-name/reginald?api_key=<MY_API_KEY>')
or
fetch('https://na1.api.riotgames.com/lol/summoner/v4/summoners/by-name/doublelift?api_key=<MY_API_KEY>')
or
fetch('https://na1.api.riotgames.com/lol/summoner/v4/summoners/by-name/faker?api_key=<MY_API_KEY>')