1. Go to this page and download the library: Download patrick-barreto/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/ */
use Http\Middleware\MiddlewareInterface;
class Middleware implements MiddlewareInterface {
public function handler($request, $callback){
//Put your code here, change the $request instance..
return $callback($request);
}
}
namespace Api\Middlewares;
use Http\Middleware\MiddlewareInterface;
class Authorization implements MiddlewareInterface {
public function handler($request, $callback){
$request->auth = $this->validadeToken($request);
return $callback($request);
}
private function validadeToken($request){
//Validade with request headers and return true or false
}
}
namespace Api\Middlewares;
use Http\Middleware\MiddlewareInterface;
class AccessTokenValidade implements MiddlewareInterface {
public function handler($request, $callback){
//Validade your accessToken
return $callback($request);
}
}
use Http\Http;
//Middlewares default
Http::middleware('AccessTokenValidade', 'Api\Middlewares\AccessTokenValidade', true);
//Middlewares to routes use.
Http::middleware('Auth', 'Api\Middlewares\Authorization');
use Http\Http;
Http::post('/createAccount', function($request) {
$return = new YourController($request);
Http::response());
Http::post('/login', function($request) {
$return = new YourController($request);
Http::response($return,
200,
[
["Content-Type" => "application/json"],
['Authorization' => $return['JWT']],
]);
});
Http::get('/users', function($request) {
$return = new YourController($request);
Http::response($return)
},
['Auth']);
Http::loadRoutesFromPath(string $dirRoutesName);
use Http\Http;
.php";
Http\Http::CORS();
Http::loadRoutesFromPath('./Routes/')
//if you need to put anything more in this system part, put here.
Http::run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.