1. Go to this page and download the library: Download tempcord/http library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tempcord / http example snippets
use Tempcord\Plugins\Http\Attributes\Route;
use Tempcord\Plugins\Http\Http\Method;
use Tempcord\Plugins\Http\Http\Response;
#[Route(Method::GET, '/health')]
final readonly class Health
{
public function __construct(private Discord $discord) {}
public function __invoke(): Response
{
return Response::json(['ready' => $this->discord->gateway->isReady()]);
}
}
#[Route(Method::GET, '/guilds/{guild}/members/{member}')]
final readonly class Member
{
public function __invoke(string $guild, string $member): Response { /* ... */ }
}
$request->method(); // 'POST'
$request->path(); // '/webhook'
$request->parameter('guild'); // a named segment
$request->query('since'); // a query string value
$request->header('X-Signature');
$request->body(); // the raw body
$request->json(); // decoded, or null when it is not JSON
$request->psr; // the PSR-7 request, for everything else
#[Route(Method::POST, '/api/links', middleware: [VerifySignature::class])]
final readonly class CreateLink { /* ... */ }
final readonly class VerifySignature implements Middleware
{
public function __invoke(Request $request, callable $next): Response
{
return $this->valid($request) ? $next($request) : Response::unauthorized();
}
}
$request->cookie('session'); // off this request's Cookie header
$request->bearerToken(); // from "Authorization: Bearer ..."
Secret::matches($configured, $request->bearerToken() ?? '');
Secret::signed($request->body(), $request->header('X-Signature') ?? '', $secret);
return Response::noContent()->withCookie(new Cookie('session', $id, secure: true));
use Tempcord\Plugins\Http\HttpConfig;
return new HttpConfig(
port: 8080,
host: '127.0.0.1',
enabled: true,
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.