Download the PHP package lukaskorl/restful without Composer

On this page you can find all versions of the php package lukaskorl/restful. 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 restful

Create RESTful API responses with ease

This package enables you to create RESTful API responses without thinking about the specifics of the underlying HTTP layer. You provide data and the package will take care of output format and status codes. In case of an application error also RESTful error reponses can be created. The package is optimized for the use with the Laravel framework. This documentation heavily focuses on the use within the Laravel framework.

Basic Usage

RESTful provides two separate functions for returning a collection or a single entity.

Returning a single entity

To return a single entity you can call the entity method on the Restful facade and provide anything that implements the ArrayAccess interface.

$response = Restful::entity([
    'name' => 'Dexter',
    'age' => 1
]);

RESTful will return a \Illuminate\Http\Response which directly extends the \Symfony\Component\HttpFoundation\Response. If you work with the Laravel 4 framework you can directly return the response object.

If you use the response object correctly the application will return:

Content-Type:application/json

{
    name: "Dexter",
    age: 1
}

Returning a collection

Analogous to the entity method the collection method accepts a collection of entities.

$response = Restful::collection([
    [
        'name' => 'Dexter',
        'age' => 1
    ],  
    [
        'name' => 'Dori',
        'age' => 1
    ],  
]);

The collection may be of the type:

The response will look like:

Content-Type:application/json

{
    data: [
        {
            name: "Dexter",
            age: 1
        },
        {
            name: "Dori",
            age: 1
        }
    ]
}

Be aware that collections are wrapped into a data attribute. This is necessary because collections may also return metadata. This metadata may include pagination information.

Usage in Laravel 4

When using RESTful in Laravel 4 you can leverage the power of Eloquent to drive your responses. Consider the following lines as result of any controller action.

return Restful::entity(Dogs::find(1));
return Restful::collection(Dogs::all());
return Restful::collection(Dogs::paginate(3));

Advanced API

Forcing output format

If you wan't to force an output format you can use the corresponding method and chain it with the output you want to serve.

return Restful::serialized()->collection(Dogs::all());
return Restful::php()->collection(Dogs::all());
return Restful::json()->collection(Dogs::all());
return Restful::jsonp('myFunction')->collection(Dogs::all());
return Restful::yaml()->collection(Dogs::all());
return Restful::xml()->collection(Dogs::all());

Content-Type header will be set automatically according to the specified format.

Errors

Also common errors can easily be handled with RESTful.

return Restful::code(404)->error("Ups");
return Restful::forbidden();
return Restful::unauthorized();
return Restful::missing();

Installation

Within Laravel 4 framework

To install RESTful simply add it as a requirement to the projects composer.json:

"require": {
    "lukaskorl/restful": "dev-develop"
}

or run composer require lukaskorl/restful.

Word of caution: RESTful is currently under heavy development. I will release a stable version 1.0.0 soon. Until then the interface may change. I do not recommend to use RESTful as a dev-develop dependency in production code.

Vanilla PHP

If you want to use RESTful in any other PHP application install it via composer as above. To use RESTful you will have to add a few more lines of code see the example code below:

<?php
require("vendor/autoload.php");
use \Lukaskorl\Restful\Facades\Vanilla as Restful;

Restful::entity(array( 'name' => 'Dexter' ))->send();

In comparison to using RESTful in a framework you don't need to return the result of the call but to directly render+send the output back to the use.

License

RESTful is open-source software licensed under the MIT license


All versions of restful with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
illuminate/support Version 4.*
illuminate/config Version 4.*
illuminate/pagination Version 4.*
symfony/http-foundation Version 2.*
jms/serializer Version 0.16.*
symfony/yaml Version 2.*
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 lukaskorl/restful contains the following files

Loading the files please wait ...