2017 © Pedro Peláez
 

library api

Helper to create APIs in Laravel.

image

sule/api

Helper to create APIs in Laravel.

  • Monday, December 15, 2014
  • by sulaeman
  • Repository
  • 1 Watchers
  • 11 Stars
  • 29 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 11 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Laravel API

Base library to start creating API using Laravel Framework. Plus support OAuth 2 authorization., (*1)

Installation

1. Composer

Open your composer.json file and add the following lines:, (*2)

{
    "require": {
        "sule/api": "2.0.0",
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "git@github.com:feelinc/laravel-api.git",
            "options": {
                "ssl": {
                    "verify_peer": "false"
                }
            }
        }
    ]
    "minimum-stability": "stable"
}e

Run composer update from the command line, (*3)

composer update

2. Service Provider & Aliases

Add the following to the list of service providers in "app/config/app.php"., (*4)

'Sule\Api\ApiServiceProvider',

Add the following to the list of aliases in "app/config/app.php"., (*5)

'API'             => 'Sule\Api\Facades\API'

3. Create Tables

Create all required tables from "TABLES.sql" file., (*6)

4. Configuration

After installing, you can publish the package's configuration file into your application, by running the following command:, (*7)

php artisan config:publish sule/api

Routes

POST /authorization, (*8)

Request Headers

User-Agent: My User Agent 
Content-MD5: md5($stringContent.$clientSecret) 

Request Body

grant_type:    client_credentials 
client_id:     JXSb6nEzpQ0e3WAWjsSsZurCaLy0knDjzkwxRlJs 
client_secret: C4vpZLRI2kncfXJQZ9l0hdnaTCTupyqF1deCVEPf 

Response Body

{
    "access_token": "jU5vKEBSPSVqRwEXwjIM0N1YefCG0hwqTK5i0UC3",
    "token_type": "bearer",
    "expires": 1399017374,
    "expires_in": 3600
}

Filters

1. api.oauth

Check route againts authorized client and passed scope, in example checking current client is having "read" scope:, (*9)

Route::get('api/v1/users', array(
    'before' => array(
        'api.oauth:read'
    ), function() {

    }
));

2. api.content.md5

Check request content signature at "Content-MD5" header. Signature should be md5($stringContent.$clientSecret), (*10)

Route::post('api/v1/users', array(
    'before' => array(
        'api.content.md5', 
        'api.oauth:write'
    ), function() {

    }
));

3. api.ua.required

Check request "User-Agent" header., (*11)

Route::post('api/v1/users', array(
    'before' => array(
        'api.ua.required', 
        'api.content.md5', 
        'api.oauth:write'
    ), function() {

    }
));

4. api.limit

Check request not exceed the limit per each client., (*12)

Route::post('api/v1/users', array(
    'before' => array(
        'api.ua.required', 
        'api.content.md5', 
        'api.limit', 
        'api.oauth:write'
    ), function() {

    }
));

Response

Return JSON response including Limiter and Access-Control-Expose-Headers header, (*13)

1. Single JSON object

return API::resourceJson($data = array(), $status = 200, array $headers = array());

2. Collection JSON object

return API::collectionJson($data = array(), $status = 200, array $headers = array());

The Versions

15/12 2014

dev-3.0/master

dev-3.0/master

Helper to create APIs in Laravel.

  Sources   Download

The Requires

 

by Avatar sulaeman

03/05 2014

dev-2.0/master

dev-2.0/master

Helper to create APIs in Laravel.

  Sources   Download

The Requires

 

by Avatar sulaeman

03/05 2014

v2.0.0

2.0.0.0

Helper to create APIs in Laravel.

  Sources   Download

The Requires

 

by Avatar sulaeman

03/05 2014

dev-1.0/master

dev-1.0/master

Helper to create APIs in Laravel.

  Sources   Download

The Requires

 

by Avatar sulaeman

03/05 2014

v1.0.0

1.0.0.0

Helper to create APIs in Laravel.

  Sources   Download

The Requires

 

by Avatar sulaeman