Core MVC, HTTP client, Session, Cookie, Config, HTTPException — 111 PHPUnit tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
||
/**
|
||
* @package Bicycle
|
||
* @author Egor Isaev
|
||
* @description IndexController.php
|
||
* @copyright (c) 03/06/2026
|
||
*/
|
||
|
||
namespace App\Controller;
|
||
|
||
use System\Classes\Controller;
|
||
use System\Classes\HTTP\Client\Curl;
|
||
use System\Classes\HTTP\Client\Request as HttpRequest;
|
||
|
||
class IndexController extends Controller
|
||
{
|
||
public function indexAction(): string
|
||
{
|
||
// GET-запрос
|
||
$response = (new Curl())->execute(
|
||
HttpRequest::factory('https://jsonplaceholder.typicode.com/todos/1')
|
||
);
|
||
|
||
$todo = $response->isSuccess() ? $response->json() : [];
|
||
|
||
return $this->render('index', ['todo' => $todo]);
|
||
}
|
||
|
||
public function postAction(): string
|
||
{
|
||
// POST с JSON-телом
|
||
$response = (new Curl())->execute(
|
||
HttpRequest::factory('https://jsonplaceholder.typicode.com/posts')
|
||
->method('POST')
|
||
->json(['title' => 'Bicycle', 'body' => 'test', 'userId' => 1])
|
||
);
|
||
|
||
$created = $response->isSuccess() ? $response->json() : [];
|
||
|
||
return $this->render('index', ['created' => $created]);
|
||
}
|
||
}
|