sinevia/php-library-api

v1.2.0 2020-04-05 13:18 UTC

This package is auto-updated.

Last update: 2024-04-05 22:10:53 UTC


README

Tests Gitpod Ready-to-Code

A package to quickly set a PHP webservice

Background

Installation

  • Install via Composer
composer require sinevia/php-library-api

Usage

  1. The lines bellow create an API service, which serves commands mapped to middleware and class methods:
$commands = [
    'ping' => 'PingController@ping',
    
    'auth/login' => 'AuthController@login',
    'auth/register' => 'AuthController@register',
    'auth/password-restore' => 'AuthController@passwordRestore',
    
    'account/password-change' => ['MiddlewareController@verifyUser','AccountController@passwordChange'],
    
];

$api = new Sinevia\ApiService;
$api->addCommands($commands);
die($api->run());
  1. Example controller with response:
class PingController{
    function ping(){
        return (new Sinevia\ApiResponse)->success('pong');
    }
}