Download the PHP package patricksavalle/slim-rest-api without Composer

On this page you can find all versions of the php package patricksavalle/slim-rest-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package slim-rest-api

Ready-to-go REST API for PHP SLIM

Uses PHP 7.x syntax

Turns the default SLIM App-class into a production-grade JSON REST-API base-class:

Very simple to use, just use the SlimRestApi-class instead of the standard Slim App-class.

Edit the slim-rest-api.ini for correct (database) configuration.

Example index.php:

<?php

declare(strict_types = 1);

namespace YourApi;

define("BASE_PATH", dirname(__FILE__));

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

use SlimRequestParams\BodyParameters;
use SlimRequestParams\QueryParameters;
use SlimRestApi\Middleware\CliRequest;
use SlimRestApi\Middleware\Cacheable;
use SlimRestApi\Middleware\ReadOnly;
use SlimRestApi\SlimRestApi;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

class YourApi extends SlimRestApi
{
    public function __construct()
    {
        // call parent ctor before anything else!
        parent::__construct();

        // Add a route
        $this->get("/echo", function (
            ServerRequestInterface $request,
            ResponseInterface $response,
            \stdClass $args)
        : ResponseInterface
        {
            return $response->withJson(QueryParameters::get());
        })
            ->add(new QueryParameters([
                '{string:.{30}},the lazy fox',
                '{mandatory_int:\d{1,10}}',
                '{char:[[:alnum:]]{1}},a',
                '{int:\int},1',
                '{bool:\bool},true',]))
            ->add(new ReadOnly);
    }
}

// instantiate and run
(new YourApi)->run();

Start the PHP server:

php -S localhost:8000

Open this URL's in your browser (see what happens):

http://localhost:8000/echo 
http://localhost:8000/echo?mandatory_int=1
http://localhost:8000/echo?mandatory_int=1&bool=false

Setup

Available Middleware

This packages comes with a minimum of (optional) helpers and middleware.

Validate parameters of a route

See: https://github.com/patricksavalle/slim-request-params

use SlimRequestParams\BodyParameters;
use SlimRequestParams\QueryParameters;

Set route to read-only

Sets route to read-only, optimising the database engine, adding a layer of robustness by preventing unwanted updates to the database.

use SlimRestApi\Middleware\ReadOnly;
$YourApp->get(...)->add( new ReadOnly );

If you use other middleware (e.g. authentication) that needs write-access, chain them AFTER this method, like so

use SlimRestApi\Middleware\ReadOnly;
$YourApp->get(...)
    ->add( new ReadOnly )
    ->add( new Authentication )
    -> ...

Set route to CLI / command-line only

Very usefull for functions that should not be exposed over HTTP (such as cronjob callbacks or configuration methods). For examples see: https://github.com/pavlakis/slim-cli

use SlimRestApi\Middleware\CliRequest;
$YourApp->get(...)->add( new CliRequest );

Available helpers

Database / PDO access

Makes database access as simple as possible. Automatically handles prepared-statement usage. Adds supersimple transaction support.

use SlimRestApi/Db;
$obj = Db::transaction(function(){
    $obj = Db::execute("SELECT * FROM yourtable LIMIT 1")->fetch();
    $obj->some_field = 'changed';
    Db::update($obj);
    return $obj;
});

All PDO-statements are accessible through the Db-singleton (magic method). To prevent warnings use:

/** @noinspection PhpUndefinedMethodInspection */

Easy query caching (using APCu).

INI-file / configuration

Makes INI's as simple as possible. Looks for a 'slim-rest-api.ini' file in the webroot, see project for axeample.

Uue SlimeRestApi/Ini;
$value = Ini::get('key');

Memcaching of methods and functions

Provides a memcached version of call_user_func_array(). Use only for true functions (i.e. code without side-effects so the result depends only on the function-argument).

use SlimRestApi/Memcache;
$value = Memcache::call_user_func_array(...);

These functions actually uses APCu as caching engine.

Contributing

Fork it.


All versions of slim-rest-api with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
slim/slim Version ^3.0
patricksavalle/slim-request-params Version *
pavlakis/slim-cli Version ^1.0
ext-pdo Version *
ext-openssl Version *
ext-json Version *
ext-apcu Version *
ext-ctype Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package patricksavalle/slim-rest-api contains the following files

Loading the files please wait ....