1. Go to this page and download the library: Download forgr/v1 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/ */
forgr / v1 example snippets
// routes/hello.php
use Forgr\Core\Request;
use Forgr\Core\Response;
function hello(Request $request): Response {
$data = $request->getBody();
$name = $data['name'] ?? 'World';
return Response::success(['message' => "Hello {$name}!"]);
}
// Register as API endpoint
post('hello');
get('function_name'); // GET route
post('function_name'); // POST route
put('function_name'); // PUT route
delete('function_name'); // DELETE route
route('name', 'PATCH'); // Custom HTTP method
$request->getBody() // JSON body as array
$request->getQuery('key') // URL parameter
$request->getMethod() // HTTP method
$request->getBearerToken() // Authorization header
Response::success($data) // 200 with data
Response::created($data) // 201 Created
Response::error($msg, $code) // Error response
Response::notFound() // 404 Not Found
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.