response->json(['message' => 'Hello, World!']); } /** * @GetMapping(path="/db") */ public function db() { return $this->response->json(World::find(random_int(1, 10000))); } /** * @GetMapping(path="/queries/[{queries}]") */ public function queries($queries = 1) { $queries = $this->clamp($queries); $rows = []; while ($queries--) { $rows[] = World::find(random_int(1, 10000)); } return $this->response->json($rows); } /** * @GetMapping(path="/fortunes") */ public function fortunes() { $rows = Fortune::all(); $insert = new Fortune(); $insert->id = 0; $insert->message = 'Additional fortune added at request time.'; $rows->add($insert); $rows = $rows->sortBy('message'); return $this->render->render('fortunes', ['rows' => $rows]); } /** * @GetMapping(path="/updates/[{queries}]") */ public function updates($queries = 1) { $queries = $this->clamp($queries); $rows = []; while ($queries--) { $row = World::find(random_int(1, 10000)); $row->randomNumber = random_int(1, 10000); $row->save(); $rows[] = $row; } return $this->response->json($rows); } /** * @GetMapping(path="/plaintext") */ public function plaintext() { return $this->response->raw('Hello, World!'); } private function clamp($value): int { if (! is_numeric($value) || $value < 1) { return 1; } if ($value > 500) { return 500; } return (int)$value; } }