Download the PHP package nvmcommunity/alchemist-restful-api without Composer
On this page you can find all versions of the php package nvmcommunity/alchemist-restful-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nvmcommunity/alchemist-restful-api
More information about nvmcommunity/alchemist-restful-api
Files in nvmcommunity/alchemist-restful-api
Package alchemist-restful-api
Short Description A library that helps you quickly get a rigorous and flexible RESTful-based API interface for your application.
License MIT
Informations about the package alchemist-restful-api
Alchemist Restful API
A library that helps you quickly get a rigorous and flexible RESTful-based API interface for your application.
Testing
This package is production-ready with 193 tests and 1151 assertions
Table of Contents
- Table of Contents
- Changelog
- Introduction
- Prerequisites
- Installation
- Laravel Integration
- Basic usage
- More explanation about each component
- Field Selector
- Resource Filtering
- Resource Pagination
- Resource Search
- Resource Sort
- License
Changelog
- 1.0.0: Initial release
- 2.0.0: Add support for new way to define object and collection field structure
- 2.0.1: Add support for AlchemistAdapter to change parameter name in request input of default components
- 2.0.16: (2024-04-28) Add more tests & fix unexpected behaviors
- 2.0.17: (2024-06-14) Fix the incorrect pattern in the field parser
- 2.0.19: (2024-06-14) Field parsing syntax supports spaces
- 2.0.20: (2024-06-14) Add a non-static version of the API class: StatefulAlchemistQueryable
- 2.0.26: (2025-03-11) Fix the incorrect validation of the field selector
- 2.0.27: (2025-04-01) Fix unreasonable null errors in field selector
Introduction
Alchemist Restful API is a library that helps you quickly get a rigorous and flexible RESTful-based API interface for your application.
The library provides a set of components that you can use to build your API interface, including:
- Field Selector: Allows your API client to select the fields they want to retrieve, ensuring that all retrieved fields are within your control.
- Resource Filtering: Focuses on checking whether the filtering that your API client is using is in the defined filterable list or not.
- Resource Sort: Support for flexible result returns with data sorted based on the sort and direction specified by the API client.
- Resource Search: When filtering through filter, the API client needs to clearly specify the filtering criteria. However, in the case of searching, the API client only needs to pass in the value to be searched for, and the backend will automatically define the filtering criteria from within.
- Resource Offset Paginator: Support pagination through the offset and limit mechanism.
Prerequisites
- PHP 7.4
- Composer installed (https://getcomposer.org)
Installation
Laravel Integration
If you are using Laravel, you can install another package called laravel-eloquent-api
to integrate Alchemist Restful API with Eloquent ORM in Laravel.
See more details about how to use nvmcommunity/laravel-eloquent-api
package at in the Laravel Eloquent API Documentation
Basic usage
Here is an example of how to use Alchemist Restful API to build a RESTful API interface for an Order API.
Step 1: Define the API class
You need to define an API class that extends the AlchemistQueryable
class and implement the methods for field selector, resource filtering, resource pagination, resource search, and resource sort.
Step 2: Validate the input parameters
Make sure to validate the input parameters passed in from the request input by using the validate
method.
Step 3: Alright, All the input parameters have been carefully validated
And finally, what you will receive here is fields, filtering, offset, search, and sort parameters from the API client. All have been carefully validated.
More explanation about each component
Below are the detailed explanations of each component that you can use to build your API interface.
Field Selector
The Field Selector component allows your API client to select the fields they want to retrieve, ensuring that all retrieved fields are within your control.
Resource Filtering
Resource Filtering focuses on checking whether the filtering that your API client is using is in the defined filterable list or not.
Filtering Rules
The filtering rules are defined based on the FilteringRules
class, which contains the following information:
- Filtering name: The name of the filtering that your API client will pass in.
- Supported operators: The list of operators that your API client can use to filter the data.
- Data type: The data type of the filtering data.
Supported filtering rules
Filtering operators
Filtering with operator in request input can be represented in form of: <filtering>:<operator>
The operators passed in from the request input (Request Operator) will be converted to the target operator.
This table also describes the structure of filtering values for special data types such as:
between
, not between
, in
, not in
Supported operators
Request Operator | Target Operator | Meaning | Value Structure |
---|---|---|---|
eq | \= | equal | \<value> |
ne | != | not equal | \<value> |
lt | \< | lower than | \<value> |
gt | > | greater than | \<value> |
lte | \<= | lower than or equal | \<value> |
gte | >= | greater than or equal | \<value> |
contains | contains (*) | contains | \<value> |
between | between (*) | between | array(\<value[0]>, \<value[1]>) |
not_between | notbetween (*)_ | not between | array(\<value[0]>, \<value[1]>) |
in | in (*) | in | array(\<value[0]>, \<value[1]>, ...) |
not_in | notin (*)_ | not in | array(\<value[0]>, \<value[1]>, ...) |
(*) Be careful with these operators because they are not native operators in any database management system; you need to handle them manually.
Resource Pagination
Support pagination through the offset and limit mechanism.
Resource Sort
Support for flexible result returns with data sorted based on the sort and direction specified by the API client.
Resource Search
When filtering through filter, the API client needs to clearly specify the filtering criteria. However, in the case of searching, the API client only needs to pass in the value to be searched for, and the backend will automatically define the filtering criteria from within.
Contributing
Please see CONTRIBUTING for details.
Contributors
Code Contributors
This project exists thanks to all the people who contribute. Contribute.
License
This Project is MIT Licensed