PHP Classes

PHP RESTful API Example: Example implementation of a REST API

Recommend this page to a friend!
  Info   View files Example   View files View files (36)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-09-29 (7 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 106 This week: 1All time: 9,686 This week: 78Up
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: 46 packages by
Country: United Kingdom
Age: 33
All time rank: 37716 in United Kingdom
Week rank: 17 Up1 in United Kingdom Up
Innovation award
Innovation award
Nominee: 17x

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  
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  /  .github  
File Role Description
Files folder imageworkflows (1 file)

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

  Files folder image Files  /  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  /  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  /  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  /  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  /  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  /  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  /  src  /  Route  /  Exception  
File Role Description
  Plain text file NotFoundException.php Class Class source

  Files folder image Files  /  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  /  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  /  src  /  Validation  
File Role Description
Files folder imageException (1 file)
  Plain text file UserValidation.php Class Class source

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

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

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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:106
This week:1
All time:9,686
This week:78Up