1. Go to this page and download the library: Download nexus-rest-api/nexus 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/ */
$middleware = function(Request $request, Closure $next) {
echo "this is a middleware function";
$next();
};
// The order of the parameters is not important
$app->get('/ping', $middleware, function(Request $request) {
return [
'code' => 'OK',
'message' => 'pong'
];
});
$findUser = function(App $app, String $id){
$app::dbConnect(); // Opens the connection with the database
// Prepared statement
$statement = $app()::db()->prepare(
'SELECT *
FROM user
WHERE id = ?'
);
$statement->bind_param('ss', $id);
$statement->execute();
$result = $statement->get_result()->fetch_all(MYSQLI_ASSOC);
$app::dbExit(); // Closes the connection with te database
return $result;
};
// Appending the module
$app::appendModule('logger', new Logger());
// Accessing the appended module
$logger = $app:
// Use case
$app->get("/users", function(Request $request) {
if(!validateToken($request->httpAuthorization))
throw new UnauthorizedException("User is not logged in");
});