1. Go to this page and download the library: Download anax/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/ */
anax / request example snippets
/**
* Configuration file for request service.
*/
return [
// Services to add to the container.
"services" => [
"request" => [
"shared" => true,
"callback" => function () {
$obj = new \Anax\Request\Request();
$obj->init();
return $obj;
}
],
],
];
// Leave to router to match incoming request to routes
$response = $di->get("router")->handle(
$di->get("request")->getRoute(),
$di->get("request")->getMethod()
);
// Send the HTTP response with headers and body
$di->get("response")->send($response);
# Create an object
$request = new \Anax\Request\Request();
# Set (reset) globals, useful in unit testing
# when not using $_GET, $_POST, $_SERVER
$request->setGlobals();
# Init the class by extracting url parts and
# route path.
$request->init();
# Get site url including scheme, host and port.
$request->getSiteUrl();
# Get base url including site url and path to current index.php.
$request->getBaseUrl();
# Get current url as base url and attach
# the query string.
$request->getCurrentUrl();
# Get script name, index.php or other.
$request->getScriptName();
# Get HTTP request method, for example
# GET, POST, PUT, DELETE.
$request->getMethod();
# Get route path as a string.
$request->getRoute();
# Get route path parts in an array.
$request->getRouteParts();
# Read a value
$value = $request->getServer($key);
# Read all values as an key value array
$array = $request->getServer();
# Read a value and use $default if $key is not set.
$value = $request->getServer($key, $default);
# Set a value
$request->setServer($key, $value);
# Read a value
$value = $request->getGet($key);
# Read all values as an key value array
$array = $request->getGet();
# Read a value and use $default if $key is not set.
$value = $request->getGet($key, $default);
# Set a value
$request->setGet($key, $value);
# Read a value
$value = $request->getPost($key);
# Read all values as an key value array
$array = $request->getGet();
# Read a value and use $default if $key is not set.
$value = $request->getPost($key, $default);
# Set a value
$request->setPost($key, $value);
# Read the body
$request->getBody();
# Read the body and treat it as json
$request->getBodyAsJson()
# Set the body
$request->setBody($content);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.