2017 © Pedro Peláez
 

library aspen

Simple PHP API framework

image

helllomatt/aspen

Simple PHP API framework

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

ASPEN

, (*1)

Aspen is and API manager and router. Make a request, and it will handle where to go for processing and returning information., (*2)

Installing

composer require helllomatt/aspen

Setting up

You need to create an index file for your project. This will load your config file and also the api endpoints you would like to use., (*3)

index.php, (*4)

<?php

namespace ASPEN;

require './vendor/autoload.php';

// If you're interested in enabling CORS
// Config::checkOrigin(Config::getOriginInformation());

Config::load('path/to/config.json');
$manager = new APIManager();
$manager->load([
    'modules/endpoint1',
    'modules/endpoint2'
]);

If you're using Apache, a .htaccess file is required for clean routing., (*5)

.htaccess, (*6)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?route=$1 [QSA]

If you're using Nginx, you need to modify your site configuration., (*7)

[todo], (*8)

Creating endpoints

Modules, plugins, addons, or whatever you call them are the separated endpoints to your API. When you define the modules to load in the index file you created above, everything there is an absolute path. The modules/ folder is just a suggestion, you can organize it however you want., (*9)

Create the modules/ folder then inside of there create a sample/ folder, leaving the full path to [ROOT]/modules/sample/., (*10)

There's a required file for an API called controller.php. That does what you think it does, controls the routing., (*11)

controller.php, (*12)

<?php

use ASPEN\API;
use ASPEN\Response;

$api = new API('Sample'); // API name (not really important)
$api->version(1);         // API version (important)

// API endpoints
$api->add((new Endpoint([
        'to'     => 'test/'
        'method' => 'get'
    ]))->then(function(Response $r) {
        $r->add("hello", "world");
        $r->success();
    }))

return $api; // VERY IMPORTANT!

Create the API object, which is just that. Then set the version. The version is important for when an endpoint is called, the version is looked at. (e.g. localhost/some-api/v1/get is different than localhost/some-api/v2/get), (*13)

Then you create your endpoints, or places that can be accessed., (*14)

curl http://localhost/aspen/v1/test

[outputs]
{
    "status": "success"
    "data": {
        "hello": "world"
    }
}

Lastly and most importantly you need to return the API object out of the file. An example of the innerworkings for this are $api = (include 'controller.php');. That lets ASPEN access the API object and work with it when routing., (*15)

The Versions

18/09 2017

dev-master

9999999-dev

Simple PHP API framework

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

api framework

18/09 2017

1.1

1.1.0.0

Simple PHP API framework

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

api framework

08/05 2017

1.0

1.0.0.0

Simple PHP API framework

  Sources   Download

MIT

The Requires

 

api framework

23/02 2017

0.5.1

0.5.1.0

Simple PHP API framework

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

api framework

09/02 2017

0.5

0.5.0.0

Simple PHP API framework

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

api framework

09/02 2017

0.4

0.4.0.0

Simple PHP API framework

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

api framework

17/01 2017

0.3

0.3.0.0

Simple PHP API framework

  Sources   Download

MIT

The Requires

 

api framework

10/01 2017

0.2

0.2.0.0

Simple PHP API framework

  Sources   Download

MIT

The Requires

 

api framework

06/01 2017

0.0.1

0.0.1.0

Simple PHP API framework

  Sources   Download

MIT

The Requires

 

api framework