Download the PHP package usox/json-schema-api without Composer

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

Unittests Scrutinizer Code Quality Code Coverage

JsonSchemaApi

This library provides a simple way to create a json api using json-schema to validate the request. You can leverage most of the input validation tasks (variables types, length/content-constraints, lists containing just certain items, etc.) to the json schema validator and work with the data right away.

Json-Schema

Every method needs a corresponding schema-file which describes, how the request data should look alike. You can find a simple example in the example/schema-folder.

Every request has also to follow a basic schema (see dist/request.json) which contains informations about the method.

Validation

Every request and the generated response will be validated against the provided schema.

Requirements

This library requires existing psr7 and psr17 implementations.

Install

Usage

Just use the factory method to create the endpoint. The factory automatically searches for a existing psr17 stream factory implementation, but you can also provide a factory instance when calling the method.

Get your method-provider ready (see below) and call the factory-method on the endpoint to retrieve a working instance:

The serve method requires a psr request and returns a psr response.

Optional: PSR15 Middleware

The endpoint class implements the PSR15 RequestHandlerInterface.

MethodProvider

The MethodProvider is the source for your api methods - this could be a simple array, a DI-Container, etc. The class has to implement Usox\JsonSchemApi\Contract\MethodProviderInterface.

API-Method

The lookup-method in the MethodProvider must return an instance of Usox\JsonSchemaApi\Contract\ApiMethodInterface.

Every api method handler must define at least those two methods:

Example

You can find a working example in the example-folder.

Just cd to the example-folder and fire up the the php internal webserver php -S localhost:8888. Now you can send POST-Requests to the api like this using curl.

Error-Handling

Basically there are three types of errors. All of them get logged.

ApiExceptions

If a handler throws an exception which extends the ApiException exception class, the api will return a Bad Request (400) response including an error message (the exception message) and an error code for reference within a json response.

InternalException

Internal errors, like non-existing schema files, invalid schemas and such, will return a Internal Server Error (500) response and create a log entry (if a logger is provided).

In addition, optionally available context information within the exception will be logged, too.

Throwable

Any Throwable which are thrown within an api handler, will be catched, logged and return a Internal Server Error (500) response.


All versions of json-schema-api with dependencies

PHP Build Version
Package Version
Requires php Version ~8.3
ext-json Version *
opis/json-schema Version ^2.1
php-http/discovery Version ^1.13
psr/http-factory Version ^1.0
psr/http-message Version ^1||^2
psr/http-server-handler Version ^1.0
psr/log Version ^1.1||^3
ramsey/uuid Version ^4.1
teapot/status-code Version ^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 usox/json-schema-api contains the following files

Loading the files please wait ....