Last active
May 28, 2020 05:11
-
-
Save ridwanbejo/9a6682e00c4965fcf3175698b4229eb3 to your computer and use it in GitHub Desktop.
bref-pokemon-api routes/web.php
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
<?php | |
/** @var \Laravel\Lumen\Routing\Router $router */ | |
/* | |
|-------------------------------------------------------------------------- | |
| Application Routes | |
|-------------------------------------------------------------------------- | |
| | |
| Here is where you can register all of the routes for an application. | |
| It is a breeze. Simply tell Lumen the URIs it should respond to | |
| and give it the Closure to call when that URI is requested. | |
| | |
*/ | |
use Illuminate\Support\Facades\Storage; | |
$router->get('/', function () use ($router) { | |
return $router->app->version()."<br /> Web service berbasis Laravel ini berjalan diatas AWS Lambda!"; | |
}); | |
$router->get('/pokemon', function () use ($router) { | |
$vals = explode("\n", Storage::disk('local')->get('pokemon.csv')); | |
$pokemons = []; | |
$num = 0; | |
foreach($vals as $data) { | |
$data = explode(",", $data); | |
if (count($data) == 1){ | |
continue; | |
} | |
if ($data[1] == "Name"){ | |
continue; | |
} | |
$pokemon = [ | |
"No" => $num, | |
"Name" => $data[1], | |
"Type1" => $data[2], | |
"Type2" => $data[3], | |
"Total" => $data[4], | |
"HP" => $data[5], | |
"Attack" => $data[6], | |
"Defense" => $data[7], | |
"SpecialAttack" => $data[8], | |
"SpecialDefense" => $data[9], | |
"Speed" => $data[10], | |
"Generation" => $data[11], | |
"Legendary" => $data[12] | |
]; | |
array_push($pokemons, $pokemon); | |
$num++; | |
} | |
return response()->json($pokemons); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment