Download the PHP package laravelista/syndra without Composer

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

Syndra

Latest Stable Version Total Downloads License Build Status

forthebadge forthebadge

Syndra is a Laravel package. It provides you with predefined JSON responses to use in your API.

Overview

When building an API you have to standardize it so that you can always expect the same response for similar requests.

When using resource controllers these methods usually are: index, store, update, destroy.

Index

For the index method you want to output data. That can be achieved with Syndra::respond($data). By default the status code is 200, but you can change it manually using Syndra::setStatusCode($statusCode)->respond($data). Syndra goes great with Fractal. To learn how to use them together read Laravel API 101.

Another thing that you will most likely want to do is to enable CORS. This can be achieved by setting the appropriate headers:

Store

In the store method you want to return that the resource was created. Syndra enables you to do this easily with Syndra::respondCreated(). This generates the following response:

You can customize the message by passing the message as a parameter Syndra::respondCreated('The resource has been created!').

Update

You can almost guess which method we use for when the resource has been updated by now; Syndra::respondUpdated(). By default this returns message Updated with status code 202. As with respondCreated, you can set the message by passing it as a parameter to respondUpdated.

Destroy

For the destroy method I like to return status code 200 with a message Ok. This can be done with Syndra::respondOk().

By applying what you have learned so far, you can now easily build your API responses however you want and they will be consistent throughout your entire API.

Advanced Usage

In this chapter I will show you how to handle most common situations which can occur in your application.

Handling Validation Errors

If you are using $this->validate($request, $rules) from your controller to validate data, you would want Syndra to return validation errors if the validation fails. To do that, go to app/Exceptions/Handler.php and in render method add this block of code:

If the validation fails, the response will be similar to the one bellow but with different messages:

Handling Model Not Found Errors

Similar to handling validation errors, model not found errors are addressed in the same way. Go to app/Exceptions/Handler.php and in render method add this block of code:

Now every time you use Model::findOrFail($id) in your controller and it does not find anything you will get this JSON response:

Handling Authentication & Authorization Errors

From your AuthController, if the authentication attempt fails you can return Syndra::respondUnauthorized() or if the authenticated user lacks permissions to do something you can return Syndra::respondForbidden(). Both methods accept message as the first parameter.

Hint! You can even pass an array instead of a string as a message.

Handling Server Errors

In the case that something goes terribly wrong, you can shamefully respond with Syndra::respondInternalError().

Installation

From the command line:

Include the service provider in config/app.php:

And add a facade alias to the same file at the bottom:

API

There are two way of working with Syndra. As a facade Syndra::respond($data) or as a injected dependency $this->syndra->respond($data):

Common responses

respond

This is useful for index and show method. Use this when you want to return custom JSON output, like the one you get from Fractal.

respondWithMessage

Use this for responding with messages. This returns a predefined message JSON template which contains the message and the status code.

Response:

respondWithError

Use this for responding with error messages. This returns a predefined error JSON template which contains the message and the status code wrapped in error.

Response:

HTTP Status Codes 2xx

respondOk

Use this to respond with a message (200).

respondCreated

Use this when a resource has been created (201).

respondUpdated

Use this when a resource has been updated (202).

HTTP Status Codes 4xx

respondUnauthorized

Use this when the user needs to be authorized to do something (401).

respondForbidden

Use this when the user does not have permission to do something (403).

respondNotFound

Use this when a resource is not found (404).

respondValidationError

Use this when the validation fails (422).

HTTP Status Codes 5xx

respondInternalError

Use this for general server errors (500).

respondNotImplemented

Use this for HTTP not implemented errors (501).

Manipulating the status code

setStatusCode

Sets status code manually. This method can be chained (combined) with other methods.

Example:

Manipulating headers

setHeaders

Sets headers on the response. This method can be chained (combined) with other methods.

Example:

Credits

Many thanks to:


All versions of syndra with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version ^5.1|^4.2
illuminate/http Version ^5.1|^4.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 laravelista/syndra contains the following files

Loading the files please wait ....