Download the PHP package baraja-core/structured-api without Composer

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

BRJ logo
BRJ organisation

Structured REST API in PHP

Integrity check

Full compatible smart structured API defined by schema.

📦 Installation & Basic Usage

This package can be installed using PackageRegistrator which is also part of the Baraja Sandbox. If you are not using it, you have to install the package manually following this guide.

A model configuration can be found in the common.neon file inside the root of the package.

To manually install the package call Composer and execute the following command:

🛠️ API endpoint

API endpoint is simple class with action methods and dependencies. For best comfort please use your custom BaseEndpoint with declaring all required dependencies.

Simple example:

Method actionDefault is used for request in format /api/v1/test with query parameter ?hello=....

Method postCreateUser will be called by POST request with all data.

Always return the response from the endpoint directly as the return type of the method. This makes static analysis easier for other tools (for example, for checking code integrity or generating documentation). The sendJson(), sendOk(), and sendError() methods are still supported, but may be marked as deprecated in the future.

📝 Endpoint registration

If you use the Nette Framework, all endpoints will be registered automatically. This provides an extension for DIC.

To register automatically, simply inherit BaseEndpoint or implement the Baraja\StructuredApi\Endpoint interface.

🌐 HTTP methods

The library supports all HTTP methods for the REST API. The selection of the HTTP method is solved by the method name.

You can specify the HTTP method at the beginning of the method name, or use an alias:

List of aliases (aliases are optional):

💾 Obtaining raw data

For processing complex data structures, it may be useful to obtain the data in its original raw form.

The library reserves the key variable array $data, which always contains the original input values from the user, regardless of validation.

For example:

✅ Validation

In the runtime, when calling methods, the passed arguments against the method definition and data types are validated. This ensures that the endpoint is never called with incorrect data.

The library guarantees that you will always get the data in the type you request. If you need to define the type more complicated, you can use a comment annotation.

Combined example:

The library takes full advantage of PHP 7 and always checks data types. If the data is passed in the wrong type (for example, a boolean cannot be passed by the GET method), it performs an automatic conversion or throws an error.

If the argument contains a default value, it is automatically marked as optional. If the user does not pass a value, the default is used. All mandatory arguments must always be passed, if not, your logic will not be called at all.

🙋 Smart response

The library contains a number of built-in methods for elegant handling of all important return states.

For example, if we want to get the detail of an article by ID and return its detail from the database, the use is completely intuitive:

Each method can return output either via send methods or directly as a type object. A more modern approach is to return the entire object, as this gives us type checking and the underlying basis for automatically generated documentation.

Warning: If you do not pass any output (by method or return statement), endpoint processing will fail.

When processing actions, it is a good idea to return success or error information:

🔒 Permissions

🚩Warning: If you do not set the rights at all, by default all endpoints are private and you must log in to call them! 👮

All API requests are validated at runtime. If you want to allow all users access to your endpoints, please add the #[PublicEndpoint] attribute to class.

For example (this endpoint will be public):

To restrict rights, define an #[Role] attribute over a class or method.

For example (only administrators and moderators can call this endpoint):

Rights settings can also be combined. For example, in a public endpoint, restrict rights to a specific method only:

🔒 Check API token

If you want to provide the API to your external partners or to provide secure communication with another application, it is a good idea to use authentication of all requests via an API token. There is an official extension structured-api-token-authorizer for this use.

🗺️ Project endpoint documentation

When developing a real application, you will often need to pass work between the backend and the frontend.

To describe all endpoints, the package offers an optional extension that generates documentation automatically based on real code scanning.

Try the Structured API Documentation.

📄 License

baraja-core/structured-api is licensed under the MIT license. See the LICENSE file for more details.


All versions of structured-api with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-json Version *
ext-mbstring Version *
ext-iconv Version *
baraja-core/service-method-invoker Version ^2.2.1
baraja-core/url Version ^1.1
baraja-core/serializer Version ^1.0
nette/di Version ^3.0
nette/http Version ^3.1
nette/application Version ^3.1
nette/robot-loader Version ^3.3
nette/caching Version ^3.1
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 baraja-core/structured-api contains the following files

Loading the files please wait ....