Download the PHP package jarischaefer/hal-api without Composer

On this page you can find all versions of the php package jarischaefer/hal-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 hal-api

HAL-API

Enhances your HATEOAS experience by automating common tasks.

About

This package is based on Laravel 5. It is designed to automate common tasks in RESTful API programming. These docs might not always be in sync with all the changes.

Installation

Requirements

Requires Laravel 5.4 and PHP 7.1.

Composer

Either require the package via Composer by issuing the following command

composer require jarischaefer/hal-api:dev-master

or by including the following in your composer.json.

Check the releases page for a list of available versions.

Service Provider

app.php

Register the Service Provider in your config/app.php file.

compile.php (optional step)

Register the Service Provider in your config/compile.php file.

Run php artisan optimize --force to compile an optimized classloader.

Usage

Simple Controller

This type of controller is not backed by a model and provides no CRUD operations. A typical use case is an entry point for the API. The following controller should be routed to the root of the API and lists all relationships.

Resource Controller

Resource controllers require three additional components:

Models

The following is a simple relationship with two tables. User has a One-To-Many relationship with Post.

Repository

You may create an Eloquent-compatible repository by extending HalApiEloquentRepository and implementing its getModelClass() method.

Searchable repository

Implementing HalApiSearchRepository enables searching/filtering by field. An Eloquent-compatible repository is available. Not restricting the searchable fields might result in information leakage.

Transformer

Transformers provide an additional layer between your models and the controller. They help you create a HAL response for either a single item or a collection of items.

Linking relationships

Overriding a transformer's getLinks method allows you to link to related resources. Linking a Post to its User:

Notice the "users.show" relation among the links.

Embedded relationships

Once data from two separate Models needs to be combined, the linking-approach doesn't quite cut it. Displaying Posts' authors (firstname and lastname in User model) becomes infeasible with more than a dozen items (N+1 GET requests to all "users.show" relationships). Embedding related data is basically the same as eager loading.

Notice the "users.show" relation in the _embedded field.

Dependency wiring

It is recommended that you wire the transformers' dependencies in a Service Provider:

routes.php

The RouteHelper automatically creates routes for all CRUD operations.

Disabling CRUD operations and pagination

Searching/filtering

The controller's repository must implement HalApiSearchRepository.

RouteServiceProvider

Make sure you bind all route parameters in the RouteServiceProvider. The callback shown below handles missing parameters depending on the request method. For instance, a GET request for a nonexistent database record should yield a 404 response. The same is true for all other HTTP methods except for PUT. PUT simply creates the resource if it did not exist before.

Exception handler

The callback above throws NotFoundHttpException if no record was found. To create a proper response instead of an error page, the exception handler must be amended. As shown below, various HTTP status codes like 404 and 422 will be returned depending on the exception caught.

Examples

JSON for a specific model (show)

JSON for a list of models (index)

Contributing

Feel free to contribute anytime. Take a look at the Laravel Docs regarding package development first. Once you've made some changes, push them to a new branch and start a pull request.

License

This project is open-sourced software licensed under the MIT license.


All versions of hal-api with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.0
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 jarischaefer/hal-api contains the following files

Loading the files please wait ....