Download the PHP package atk4/api without Composer

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

Agile API Framework

Build Status StyleCI codecov Code Climate Issue Count

License GitHub release

End-to-end implementation for your RESTful API and RPC. Provides a very simple means for you to define API end-points for the application that already uses Agile Data.

1. Simple To Use

Agile API strives to be very simple and work out of the box. Below is a minimal code to get your basic API going, put that into v1.php file then invoke composer require Atk4/Api :

2. Agile Data Integration

Agile Data is a data persistence framework. In simple terms, you can use Agile Data to create your business models (entities) and interact with the database. Agile API is designed to be a perfect integration if you are have already defined classes and persistence in Agile Data. Next code assumes you have Model Country and Persistence $db:

This creates a standard standard-compliant RESTful interface for interfacing the client model:

Through Agile UI you may add conditions, limits and more. Also second argument can be a call-back:

Field types, data conversions, validation and hooks can all be defined through Agile Data, making the API layer very transparent and simple. If you attempt to load non-existant record, API will respond with 404. Other errors will be properly mapped to the API codes or fallback to 500.

Work in progress

Agile UI is still a work in progress. This readme will be further updated to reflect a current features.

Planned Features

Agile API is in development but the following features are planned:

Simple to use

To set up your API, simply create new RestAPI class instance and define routes. You can enable versioning by creating "v1" folder and placing index.php in that folder. Some things work and we do not want to re-invent them!

Calling methods such as get(), post() with a function call-back will register them and if URL matches a pattern, all the matching callbacks will be executed, that is, until some of them will present a return value.

Execution will occur as soon as the match is confirmed (to help with error display).

Technically this allows multiple call-backs to be matched:

Note, that some popular PHP API frameworks (like Slim) use {name} for matching parameters, however rest of IT industry prefers using ":name" instead. We will use industry pattern matching, but will try to also support {$foo}, although it does look too similar to Agile UI template tags.

I think that the methods can be cleverly made to match the rules too:

A useful note about match is that it can be used without action and will return true/false.

Model Routing

Method rest() implements a standard Restful API end-point dedicated to a model. There are two ways to use it:

This would simple enable all the necessary operations for accessing the model, in particular:

You can also specify a different field if you don't want to use primary key:

Agile Data offers powerful ways of traversing references, and the above approach can also utilize:

This would create new route for URLs such as /clients/123/orders/395. The model for the client with id 123 would be loaded first, then ref('Orders') would be executed. The rest of the logic is similar to before.

This gives us option to perform deep traversal too:

This would load the Client, perform ref('Orders')->ref('Payments'). Finally, the "id" is optional:

Sometimes you would want to have even more control, so you can use:

Method rest() builds on top of methods put(), get(), post() and others. Third argument to method rest() can specify array with options.

Auth

Our API supports various authentication methods. Some of them are built-in and 3rd party extensions can also be used.

Lets look at the very basic user/password authentication.

You can place the authentication method strategically, and it will protect all the further routes but not the ones above it. Also you can use a custom route if you wish to only protect some portion of your API.

The method AUTH will look for HTTP_AUTH headers and will respond with 405 code if user record cannot be loaded with a corresponding user/password combination.

After user authentication is performed, $app->user will exist:

Rate Limit

Rate Limit support will limit number of requests which user (or IP) can make. It's easy to set it up:

It's preferable to use rate limits with persistence such as Redis or Memcache:

Deep logging

Agile Data already supports audit log, but with Agile API you can compliment that even further:

This would create a log entry per invocation and use it for all the subsequent changes inside data persistence.

Note that the $audit_id produced by the above function can also be used for UNDO action:

which would also reverse all the changes done on the persistence layer.

Error Logging

Similarly to Agile UI, the application for API will catch exceptions raised.

System support and global scoping

Agile Data supports global scoping, so you can add additional hook that would affect creation of all the models and add some further conditioning. That's useful based off the Auth response:

Mapping to file-system

Optional Arguments

Agile API supports various get arguments.

Handling of those arguments happens inside function args(). It's passed in a Model, so it will look at the GET arguments and perform the necessary changes.

Other points

Agile API is JSON only. You might be able to add XML output, but why.

Agile API does not use envelope. Response data will be "[]" for empty result. If there is a problem with response, you'll get it through status code, in which case output will change.

Agile API does not support HATEOAS. Technically you should be able to add support for it, but it would require a more complex mapping or extra code. We prefer to keep things simple.

Agile API will pretty-print JSON by default, so make sure "gzip" is enabled.

Agile API will accept either raw JSON or Form encoded input, but examples will always use JSON

Agile API does not use "pagination" instead "limit" and "skip" values. You can introduce pages if you wish.

Deep-loading resources is something that you can add. For instance if you load "Invoice" it may contain "lines" array containing list of hashes. Documentation will be provided on how to make this possible. There will also get argument to instruct if deep-loading is needed.

Errors and exceptions will contain "error", "message" and "args" keys. Optional key "raised_by" may contain another object with same keys if said error was raised by another error. Another possibility is "description" field.

(see http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api)

https://www.reddit.com/r/PHP/comments/32tbxs/looking_for_php_rest_api_framework/

testing / behat: http://restler3.luracast.com/examples/_001_helloworld/readme.html

URL patterns

Here are some examples

Route Groups

It's possible to divert route group to a different App.

You can also divert


All versions of api with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.0
atk4/data Version ^2.0
zendframework/zend-diactoros Version ^1.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 atk4/api contains the following files

Loading the files please wait ....