Download the PHP package otezvikentiy/json-rpc-api without Composer
On this page you can find all versions of the php package otezvikentiy/json-rpc-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package json-rpc-api
OtezVikentiy Symfony Json RPC API Bundle
The bundle allows you to quickly and conveniently create JSON RPC API applications based on the Symfony framework.
Features
- [x] easy api versioning
- [x] easy bundle installation
- [x] compatible with attributes
- [x] compatible with POST, GET, PUT, PATCH, DELETE requests
- [x] fully compatible with https://www.jsonrpc.org/specification
- [x] swagger openapi out of the box
- [x] callbacks
github: https://github.com/OtezVikentiy/symfony-jsonrpc-api-bundle
Bundle installation
see how to easily install bundle.
Examples
During the installation process, we defined the src/RPC/V1/{*Method.php}
directory in the services and marked with
tags in it all the classes ending in *Method.php
- these will be our API endpoints.
link | description | files list | curl |
---|---|---|---|
see example | Base easiest example. | Request.php, Response.php, GetProductsMethod.php | curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc": "2.0","method": "getProducts","params": {"title": "AZAZAZA"},"id": 1}' http://localhost/api/v1 |
see example | Example with callbacks. | Request.php, Response.php, GetProductsMethod.php, AbstractMethod.php | curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc": "2.0","method": "getProducts","params": {"title": "AZAZAZA"},"id": 1}' http://localhost/api/v1 |
see example | Example when you need to give in response not single object, but a number of objects. | Request.php, Response.php, GetProductsMethod.php, Product.php | curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc": "2.0","method": "getProducts","params": {"title": "AZAZAZA"},"id": 1}' http://localhost/api/v1 |
see example | Sometimes you may need to return from API not only a json response, but a picture or a document for example. In such a case you can use this example. | Request.php, ErrorResponse.php, PlainResponse.php, GetProductsMethod.php | curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc": "2.0","method": "getProducts","params": {"title": "AZAZAZA"},"id": 1}' http://localhost/api/v1 |
Swagger
If you wish to generate openapi swagger yaml file - then run this command:
It would generate a swagger file public/openapi/api_v1.yaml
which you can use in your swagger instance.
see example of how to combine multiple endpoints with tags
see example how to define default, format and example for scalar properties of response
see example how to describe array properties of response
Security
Initially, two implementation options are provided and tested, described below, but you are free to connect any other software solutions to your taste and color.
Auth via lexik jwt token bundle
Auth via self-written system
You may need to add a role model to restrict user access. You always have the option to implement your own version, but there is also a built-in implementation based on the simplest Symfony Security version.
Built-in roles usage example
All versions of json-rpc-api with dependencies
doctrine/annotations Version ^2.0
symfony/framework-bundle Version >=6.3
symfony/yaml Version >=6.3
symfony/validator Version >=6.3
symfony/serializer Version >=6.3
symfony/console Version >=6.3
symfony/security-bundle Version ^7.1