PHP code example of fastpress / request

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

    

fastpress / request example snippets


use Fastpress\Http\Request;

$request = new Request();

$isValid = $request->validateCsrf();

generateCsrfToken(): string

$token = $request->generateCsrfToken();

$name = $request->input('name');
$age = $request->input('age', 25);
$rawInput = $request->input('comment', null, false); 

$uploadedFile = $request->file('image');

hasFile(string $key): bool

if ($request->hasFile('document')) {
  // Process the file
}

if ($request->isJson()) {
  // Process the JSON data
}

$method = $request->getMethod(); 

$ipAddress = $request->getIp();

if ($request->accepts('application/json')) {
  // Send JSON response
}

$page = $request->get('page', 1);

$email = $request->post('email');

$userId = $request->json('user_id');

$requestBody = $request->getBody();

$rules = [
  'name' => 'email',
];

$errors = $request->validate($rules);

if (!empty($errors)) {
  // Handle validation errors
}

$request->setUrlParams(['id' => 10, 'slug' => 'my-article']);

$articleId = $request->param('id');

$allInputData = $request->all();