PHP code example of rammewerk / http

1. Go to this page and download the library: Download rammewerk/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/ */

    

rammewerk / http example snippets


use Rammewerk\Http\RequestFactory;
$request = RequestFactory::create();

$path = $request->path(); // e.g., 'profile/settings'
$domain = $request->domainName(); // e.g., 'example.com'
$subdomain = $request->subdomain(); // e.g., 'api' from 'api.example.com'
$isSubdomain = $request->isSubdomain('api'); // true if subdomain is 'api'

$name = $request->input('name'); // Get input from query or request body
$allInputs = $request->all(); // Get all inputs
$file = $request->file('avatar'); // Get uploaded file (returns Symfony\Component\HttpFoundation\File\UploadedFile)

$name = $request->inputString('name'); // Get input as a string
$age = $request->inputInt('age'); // Get input as an integer
$price = $request->inputFloat('price'); // Get input as a float
$isActive = $request->inputBool('is_active'); // Get input as a boolean
$tags = $request->inputArray('tags'); // Get input as an array
$date = $request->inputDateTime('date', 'Y-m-d'); // Get input as a DateTimeImmutable object
$email = $request->inputEmail('email'); // Get input as a validated email string

$token = $request->generateCsrfToken(); // Generate a CSRF token
$request->validateCsrfToken(); // Validate the CSRF token from the request

use Rammewerk\Http\RequestFactory;
use App\Entity\User;

$request = RequestFactory::create();

// Simple hydration where each input key is mapped to an entity property
$user = $request->decode(User::class);

// More advanced hydration with custom mapping and onfig->exclude('password'); // Exclude 'password' from being set
});

// $user is now an instance of App\Entity\User populated with data from the request

$request->flash('success', 'User created successfully!');
$messages = $request->getFlashMessages(); // Get all flash messages

$isHtmxRequest = $request->htmxRequest();
$currentUrl = $request->htmxCurrentUrl();
$historyRestoreRequest = $request->htmxHistoryRestoreRequest();
$promptResponse = $request->htmxPromptResponse();
$request = $request->htmxRequest();
$targetId = $request->htmxTargetId();
$triggerName = $request->htmxTriggerName();
$triggerId = $request->htmxTriggerId();

use Rammewerk\Http\Response;
$response = new Response('Hello, world!');
$response->send();

$response = new Response();
$redirectResponse = $response->redirect('/dashboard');
$redirectResponse->send();

$response->htmxRedirect('/new-page');
$response->htmxRefresh();
$response->htmxLocation('/profile', ['userId' => 123]);
$response->htmxPushUrl('/new-url');
$response->htmxReplaceUrl('/old-url');
$response->htmxReswap('innerHTML');
$response->htmxRetarget('#target-element');
$response->htmxTriggers(['event1', 'event2']);
$response->htmxAfterSettleTriggers('afterSettleEvent');
$response->htmxAfterSwapTriggers(['afterSwap1', 'afterSwap2']);

use Rammewerk\Http\Response;
Response::pageNotFound('Page not found');