PHP Classes

PHP RESTful API Example: Example implementation of a REST API

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 109 All time: 9,659 This week: 40Up
Version License PHP version Categories
php-restful-api 1.0GNU General Publi...7Libraries, Web services, PHP 7
Description 

Author

This package provides an example implementation of a REST API.

It provides classes to route API requests to service classes.

This is the source code of my Udemy course, where I teach how to build a real-world RESTful API with PHP 8.2 from scratch.

Picture of Pierre-Henry Soria
  Performance   Level  
Name: Pierre-Henry Soria <contact>
Classes: 49 packages by
Country: United Kingdom
Innovation award
Innovation award
Nominee: 18x

Winner: 3x

Example

<?php
namespace PH7\ApiSimpleMenu;

use
Whoops\Run as WhoopsRun;
use
Whoops\Handler\JsonResponseHandler as WhoopsJsonResponseHandler;

require
__DIR__ . '/vendor/autoload.php';

// handle all exceptions and convert them into JSON format
$whoops = new WhoopsRun();
$whoops->pushHandler(new WhoopsJsonResponseHandler);
$whoops->register();


Details

Build a PHP RESTful API

This is the source code of my Udemy course Build a Modern REST API with PHP 8.2 ?

Diagram showing example of REST API architecture

The course

It is indispensable to enroll the Udemy course in order to understand and setup properly this project.

Quick Setup

  • Composer & `composer install`
  • Run the in-built PHP server `php -S localhost:8080`

Author

Pierre-Henry Soria. A super passionate and enthusiastic software engineer! ? Also, a true cheese ?, dark chocolate, and espresso lover! ??

License

This source code is distributed under the open-source MIT license.


  Files folder image Files (36)  
File Role Description
Files folder image.github (1 directory)
Files folder imagesrc (1 file, 7 directories)
Files folder imagetests (1 directory)
Accessible without login Plain text file .env.dist Data Auxiliary data
Accessible without login Plain text file .htaccess Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file example-web-app-RE...PI-architecture.svg Data Auxiliary data
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file license.md Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file readme.md Doc. Documentation

  Files folder image Files (36)  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files (36)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file ci-test.yml Data Auxiliary data

  Files folder image Files (36)  /  src  
File Role Description
Files folder imageconfig (2 files)
Files folder imageDal (3 files)
Files folder imageEntity (3 files)
Files folder imagehelpers (2 files)
Files folder imageRoute (5 files, 1 directory)
Files folder imageService (3 files, 1 directory)
Files folder imageValidation (1 file, 1 directory)
  Plain text file AllowCors.php Class Class source

  Files folder image Files (36)  /  src  /  config  
File Role Description
  Accessible without login Plain text file config.inc.php Example Example script
  Accessible without login Plain text file database.inc.php Example Example script

  Files folder image Files (36)  /  src  /  Dal  
File Role Description
  Plain text file FoodItemDal.php Class Class source
  Plain text file TokenKeyDal.php Class Class source
  Plain text file UserDal.php Class Class source

  Files folder image Files (36)  /  src  /  Entity  
File Role Description
  Plain text file Entitable.php Class Class source
  Plain text file Item.php Class Class source
  Plain text file User.php Class Class source

  Files folder image Files (36)  /  src  /  helpers  
File Role Description
  Accessible without login Plain text file headers.inc.php Example Example script
  Accessible without login Plain text file misc.inc.php Aux. Auxiliary script

  Files folder image Files (36)  /  src  /  Route  
File Role Description
Files folder imageException (1 file)
  Accessible without login Plain text file food-item.routes.php Example Example script
  Plain text file Http.php Class Class source
  Accessible without login Plain text file not-found.routes.php Aux. Auxiliary script
  Accessible without login Plain text file routes.php Example Example script
  Accessible without login Plain text file user.routes.php Example Example script

  Files folder image Files (36)  /  src  /  Route  /  Exception  
File Role Description
  Plain text file NotFoundException.php Class Class source

  Files folder image Files (36)  /  src  /  Service  
File Role Description
Files folder imageException (3 files)
  Plain text file FoodItem.php Class Class source
  Plain text file SecretKey.php Class Class source
  Plain text file User.php Class Class source

  Files folder image Files (36)  /  src  /  Service  /  Exception  
File Role Description
  Plain text file CannotLoginUserException.php Class Class source
  Plain text file CredentialsInvalidException.php Class Class source
  Plain text file EmailExistsException.php Class Class source

  Files folder image Files (36)  /  src  /  Validation  
File Role Description
Files folder imageException (1 file)
  Plain text file UserValidation.php Class Class source

  Files folder image Files (36)  /  src  /  Validation  /  Exception  
File Role Description
  Plain text file InvalidValidationException.php Class Class source

  Files folder image Files (36)  /  tests  
File Role Description
Files folder imageEntity (2 files)

  Files folder image Files (36)  /  tests  /  Entity  
File Role Description
  Plain text file ItemTest.php Class Class source
  Plain text file UserTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:109
This week:0
All time:9,659
This week:40Up