[request] Add short name that used as access key in object with character's data
muirch opened this issue ยท 1 comments
Hi ๐
When I get data of character with long name (e.g. Kamisato Ayaka), also I want to get image of this character. In this case I need to make request that look like "https://api.genshin.dev/characters/ayaka/icon", but when I'm trying to do it programmatically (js):
const character = {...} // stored character's data got from api
const img = fetch(`https://api.genshin.dev/characters/${character.name}/icon`);
request looks like "https://api.genshin.dev/characters/Kamisato%20Ayaka/icon", even if I remove space and convert name to lower case, I can't get image due to mismatch with full name in character's data and short name that used as id for accessing data. In this case name is "Kamisato Ayaka" and short id name is "ayaka"
Solution is simple: I need to use constructions like switch or if-else like:
let idName = "";
// set proper key
if (character.name == "Kamisato Ayaka") {
idName = "ayaka";
}
// then make request
const img = fetch(`https://api.genshin.dev/characters/${idName}/icon`); // https://api.genshin.dev/characters/ayaka/icon
but it looks ugly and not scalable in a long term.
Is it possible to make character's name and key name the same or add id name in character's data?
{
"id": "ayaka",
"name": "Kamisato Ayaka"
}