Here is an example of my URL:
https://my-website.com/api/players?countryId=1&clubId=2&playerName=abc
The parameter values can vary.
This is the code snippet I use:
getDataPlayer(payload) {
let params
if(payload.countryId && payload.clubId && payload.playerName)
params = `countryId=${payload.countryId}&clubId=${payload.clubId}&playerName=${payload.playerName}`
return axios.get(`https://my-website.com/api/players?${params}`)
.then(response => {
return response.data
})
},
When I console.log(payload), the output appears as follows:
{countryId: "1", clubId: "2", playerName: "ronaldo"}
The payload is adaptable and can be:
{countryId: "1", clubId: "2"}
or
{playerName: "ronaldo"}
Is there a more straightforward approach, or do I need to include multiple conditions in the getDataPlayer method?