📜 ⬆️ ⬇️

Platform to quickly create a RESTful API

Over the past few years I have had to create many APIs in PHP. Most of them were RESTful. The first time it was interesting - hours of discussion of the format of the response, the content of errors, authorization options and other romance. The second time did not leave the feeling of deja vu. For the third time it was already clear - something needs to be changed ...

Well, for the fourth time, when I was given the task of creating an API, in parallel with the development of the main project, I started to create a universal platform for creating an API in which all the “main” issues will be solved:

  1. Answer format (including errors)
  2. Date formatting
  3. Records management
  4. Authorization and Authentication
  5. Validation of requests
  6. and much more

As a pragmatic person, at first I looked for what is ready. Something is there.
')

api-platform


Website: api-platform.com
Very powerful solution. Made on the basis of the symfony php framework. There is everything you need and even more. Probably for those who love programming through configurations and symfony, this is what you need. Alas, I do not belong to this category.

apigility


Website: apigility.org
No less powerful solution. This time, based on the Zend framework. It's even some kind of CMS for creating an API, with both RESTful and RPC. Probably for those who love programming with a mouse, this is what they need. Alas, I do not belong to this category either.

There are other solutions, here is a good selection .

But in the end, nothing lovely my heart could not choose. But they managed to form several principles and requirements for the future project:

  1. Code, not annotations and configurations
  2. No ui
  3. Creating a complete API with one team
  4. Autogeneration documentation. Desirable by code, not from annotations
  5. Simplicity
  6. Minimum bicycle

My decision


I did not discover America. I simply took the good components, assembled them together, wrote all the necessary boilerplate code for the work and assembled the composer project.

The cornerstone is the jsonapi presentation standard . With the help of it, almost all "holivarny" issues have been resolved. It only remains for me to decide on the format of requests with filtering, sorting and page-by-page navigation. The json-api package from neomerx is responsible for the output (By the way, not too long ago he also collected his api starter pack ).

As a basis, I chose Slim3 . Competently designed, fast, easy to expand and simple.

To work with the database ORM Eloquent . Convenient, relatively fast and easy.

Work with rights and access control built on the basis of Zend ACL . Surprisingly simple package for working with rights.

JWT Token Based Authorization

Documentation is generated by comments written in code using ApiDocJS . Why not swagger? I tried it, but I liked the apidoc more.

The code is placed on github , the project is available on packagist .

Immediately after installation, you will have a completely ready API with everything you need. I would be glad if someone applied the package in the work. I have already managed to do 1 project on it (+ the project that I did in parallel with bootstrapi) - the flight is normal.

Source: https://habr.com/ru/post/318724/


All Articles