Created
March 19, 2026 11:46
-
-
Save davlgd/6da31eb6789948db3ba6c7f22731bd5b to your computer and use it in GitHub Desktop.
Test Otoroshi JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exports.on_backend_call = function(ctx) { | |
| const name = (ctx.request.query.name && ctx.request.query.name[0]) | |
| ? ctx.request.query.name[0].toLowerCase() | |
| : 'pikachu'; | |
| let pokemon = null; | |
| fetch('https://pokeapi.co/api/v2/pokemon/' + name) | |
| .then(function(r) { return r.json(); }) | |
| .then(function(data) { pokemon = data; }); | |
| if (!pokemon || pokemon.detail) { | |
| return { | |
| status: 404, | |
| headers: { 'Content-Type': 'application/json' }, | |
| body_json: { error: 'Pokemon not found', name: name } | |
| }; | |
| } | |
| return { | |
| status: 200, | |
| headers: { 'Content-Type': 'application/json' }, | |
| body_json: { | |
| name: pokemon.name, | |
| id: pokemon.id, | |
| types: pokemon.types.map(function(t) { return t.type.name; }), | |
| stats: pokemon.stats.map(function(s) { | |
| return { name: s.stat.name, value: s.base_stat }; | |
| }), | |
| height: pokemon.height, | |
| weight: pokemon.weight, | |
| sprite: pokemon.sprites.front_default | |
| } | |
| }; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment