Download the PHP package kelemen/api-nette without Composer

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

Api Nette

Highly customizable and easy to setup REST api handling for Nette framework.

Scrutinizer Code Quality Code Coverage Build Status Packagist

SensioLabsInsight

Installation

Prepare to use

  1. First of all you need an Api presenter for handle api requests. You can use Kelemen\ApiNette\Presenter\ApiPresenter or write you own.
  2. Register new mapping in config.neon

  3. Add api route to router. We use keyword api for identify api requests.

  4. Configure Api (example from config.neon)

Api routes

Add routes to api

REST api routes can be defined with shortcut functions (for most used HTTP methods):

Or you can add any HTTP method processing with add($method, $pattern, $handler, $params = []) function.

Route patterns

In route definition you can use regular patterns or define parameters closed in < and >. Routes are evaluated in order they was added. So define specific routes first.

Route handlers

Route definition use lazy loading from Nette DI Container. Handlers are defined by type or by name registered in config.neon file. For name definition, prefix service name with #.

Route parameters

As parameter is now accepted only middleware key. Middleware definition use same lazy loading logic as handlers.

Handler

Handler provide business logic for resolved api route.

Validations

IMPORTANT! Every parameter is parsed as string! So use numeric validation rule instead of integer or float.

Primary validation is handled by Nette Validators. Validations are registered in handlers validate() function. All validated input parameters are accessible in handler via $this->values array.

If any validation failed, api automatically send response with 400 HTTP code with all validation errors.

Custom validation rules

By default you don't need to register new Validator instance to Api. But if you want register new validations or override existing validations you need to create and configure your own Validator instance.

Inputs

Validator has defined set of default inputs

Keyword Description
get $_GET
post $_POST
cookie $_COOKIES
file $_FILES
postRaw file_get_contents("php://input")
json json_decode(file_get_contents("php://input"), true)
path Parsed params from matched route

If you want some special input you can add this input to Validator with setInput($name, InputInterface $input) function.

Middleware

Api flow can be extended by middleware. Middleware interface has only one function __invoke(Request $request, Response $response, callable $next). How middleware works:

If we have 3 middlewares registered as

Flow will look like:

Flow and Exceptions

Library is shipped with default api presenter Kelemen\ApiNette\Presenter\ApiPresenter. This presenter running api and handle all exceptions (create response depends on catched exception). If you want custom error responses, create and register your own presenter.

Api throws this exceptions

Exception Description
Kelemen\ApiNette\Exception\ApiNetteException Base parent exception
Kelemen\ApiNette\Exception\UnresolvedHandlerException Handler registered for resolved route doesn't exists in container
Kelemen\ApiNette\Exception\UnresolvedMiddlewareException Middleware registered for resolved route doesn't exists in container
Kelemen\ApiNette\Exception\UnresolvedRouteException None of the registered routes match given url
Kelemen\ApiNette\Exception\ValidationFailedException Some of registered validations failed
Kelemen\ApiNette\Exception\ValidatorException Input type use in validation is not registered in validator
Kelemen\ApiNette\Exception\MiddlewareException Middleware configuration/processing exception

Base Implementations

Middleware

CORSMiddleware

Setup Access-Control-Allow-Origin and Access-Control-Allow-Credentials headers. Middleware has 3 modes:

Handler

OptionsPreflightHandler

Configurable handler for browser CORS preflight request. Configurable response headers:


All versions of api-nette with dependencies

PHP Build Version
Package Version
Requires php Version >= 5.6
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 kelemen/api-nette contains the following files

Loading the files please wait ....