PHP Classes

File: routes/api.php

Recommend this page to a friend!
  Classes of Ujah Chigozie peter   Luminova REST API Example   routes/api.php   Download  
File: routes/api.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Luminova REST API Example
Implements an example of a REST API
Author: By
Last change:
Date: 17 days ago
Size: 1,174 bytes
 

Contents

Class file image Download
<?php
use \Luminova\Routing\Router;
/**
 * This file handles all URI that start with `api` (e.g, https://example.com/api)
 *
 * The following global variables are available in the current file:
 *
 * @var \Luminova\Routing\Router $router The routing instance.
 * @var \App\Application $app The application instance that provides access to the overall application context.
 * @var string $context The name of the current routing context (this file's context).
 */

 
$router->any('/', 'RestController::index');

 
$router->bind('/v1/posts', function(Router $router) {
   
$router->middleware(Router::ANY_METHODS, '/(:root)', 'RestController::auth');
   
   
// CRUD routes for posts
   
$router->get('/', 'RestController::list'); // Retrieve all posts
   
$router->get('/(:int)', 'RestController::read'); // Retrieve a specific post by ID
   
$router->post('/create', 'RestController::create'); // Create a new post
   
$router->put('/update/(:int)/(:int)', 'RestController::update'); // Update an existing post
   
$router->delete('/delete/(:int)/(:int)', 'RestController::delete'); // Delete a post by ID
 
});