Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion App/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ public function show(Request $request)
'user' => $user
]);
}
}

public function create(Request $request)
{
$user = (new User)->create([
'name' => $request->input('name'),
]);
return json_encode($user);
}
}
5 changes: 5 additions & 0 deletions config/server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'base_url' => "http://localhost:8000"
];
Binary file modified database/app.sqlite
Binary file not shown.
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
$router->get('/', [NameController::class, 'index']);
$router->get('/users', [UserController::class, 'index']);
$router->get('/users/{id}', [UserController::class, 'show']);
$router->post('/user', [UserController::class, 'create']);
return $router;
26 changes: 26 additions & 0 deletions scripts/http
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env php
<?php

$config = require __DIR__ . '/../config/server.php';

function send_request(string $query, string $method, string $params = "{}")
{
global $config;

$url = $config['base_url'] . $query;
$data = http_build_query(json_decode($params, true) ?? []);

$options = [
'http' => [
'header' => "Content-Type: application/json\r\n",
'method' => $method,
'content' => $data,
],
];

$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
echo $response;
}

send_request($argv[1], $argv[2], $argv[3] ?? "{}");