PHPackages                             nvmcommunity/alchemist-restful-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. nvmcommunity/alchemist-restful-api

ActiveLibrary[HTTP &amp; Networking](/categories/http)

nvmcommunity/alchemist-restful-api
==================================

A library that helps you quickly get a rigorous and flexible RESTful-based API interface for your application.

2.0.31(1mo ago)59945112MITPHPPHP &gt;=7.4

Since Mar 4Pushed 6mo ago2 watchersCompare

[ Source](https://github.com/nvmcommunity/alchemist-restful-api)[ Packagist](https://packagist.org/packages/nvmcommunity/alchemist-restful-api)[ RSS](/packages/nvmcommunity-alchemist-restful-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (10)Versions (63)Used By (2)

Alchemist Restful API
=====================

[](#alchemist-restful-api)

[![Project Contributors](https://camo.githubusercontent.com/dc658d025ea33bade406f31bf13cb9a36fd3b184db41b713e762132665b3d5c0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f6e766d636f6d6d756e6974792f616c6368656d6973742d7265737466756c2d617069)](https://camo.githubusercontent.com/dc658d025ea33bade406f31bf13cb9a36fd3b184db41b713e762132665b3d5c0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f6e766d636f6d6d756e6974792f616c6368656d6973742d7265737466756c2d617069)[![Project License](https://camo.githubusercontent.com/3017e0b058898916c8fe527d636eb139e6d772bad067e9a253879df5ac08c151/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e766d636f6d6d756e6974792f616c6368656d6973742d7265737466756c2d617069)](https://camo.githubusercontent.com/3017e0b058898916c8fe527d636eb139e6d772bad067e9a253879df5ac08c151/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e766d636f6d6d756e6974792f616c6368656d6973742d7265737466756c2d617069)

[![Project Stars](https://camo.githubusercontent.com/4be4270c78191e90b412f01b469fcfc5b84fc1b94d2195f806ec113b9dce7d3b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6e766d636f6d6d756e6974792f616c6368656d6973742d7265737466756c2d617069)](https://camo.githubusercontent.com/4be4270c78191e90b412f01b469fcfc5b84fc1b94d2195f806ec113b9dce7d3b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6e766d636f6d6d756e6974792f616c6368656d6973742d7265737466756c2d617069)[![Project Forks](https://camo.githubusercontent.com/6c9ee3e6a044bcdb0b2669b70fa55b5ce66f99282abdf0084ecd099f2e0c4e23/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6e766d636f6d6d756e6974792f616c6368656d6973742d7265737466756c2d617069)](https://camo.githubusercontent.com/6c9ee3e6a044bcdb0b2669b70fa55b5ce66f99282abdf0084ecd099f2e0c4e23/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6e766d636f6d6d756e6974792f616c6368656d6973742d7265737466756c2d617069)[![Project Watchers](https://camo.githubusercontent.com/8338081fae369df8cdb55f0341d4e1f1473fc70f416930e907b16a7fa201919c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f77617463686572732f6e766d636f6d6d756e6974792f616c6368656d6973742d7265737466756c2d617069)](https://camo.githubusercontent.com/8338081fae369df8cdb55f0341d4e1f1473fc70f416930e907b16a7fa201919c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f77617463686572732f6e766d636f6d6d756e6974792f616c6368656d6973742d7265737466756c2d617069)[![Project Issues](https://camo.githubusercontent.com/c70dd3a7ce2f7a659137ed8b1c6ac1c984e3ca5974f41688efac2c76e61be465/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6e766d636f6d6d756e6974792f616c6368656d6973742d7265737466756c2d617069)](https://camo.githubusercontent.com/c70dd3a7ce2f7a659137ed8b1c6ac1c984e3ca5974f41688efac2c76e61be465/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6e766d636f6d6d756e6974792f616c6368656d6973742d7265737466756c2d617069)

A library that helps you quickly get a rigorous and flexible RESTful-based API interface for your application.

Testing
-------

[](#testing)

This package is production-ready with 193 tests and 1151 assertions

```
./vendor/phpunit/phpunit/phpunit
```

Table of Contents
-----------------

[](#table-of-contents)

- [Table of Contents](#table-of-contents)
- [Changelog](#changelog)
- [Introduction](#introduction)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Laravel Integration](#laravel-integration)
- [Basic usage](#basic-usage)
- [More explanation about each component](#more-explanation-about-each-component)
    - [Field Selector](#field-selector)
    - [Resource Filtering](#resource-filtering)
    - [Resource Pagination](#resource-pagination)
    - [Resource Search](#resource-search)
    - [Resource Sort](#resource-sort)
- [License](#license)

Changelog
---------

[](#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](./docs/changelogs/2_0_1_Add_support_for_Adapter_to_change_parameter_name_in_request_input.md)
- **2.0.16**: (2024-04-28) Add more tests &amp; 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
- **2.0.30**: (2025-10-23) Refactor: Decouple AlchemistRestfulApi from concrete component implementations

Introduction
------------

[](#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
-------------

[](#prerequisites)

- PHP 7.4
- Composer installed ([https://getcomposer.org](https://getcomposer.org/))

Installation
------------

[](#installation)

```
composer require nvmcommunity/alchemist-restful-api
```

Laravel Integration
-------------------

[](#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.

```
composer require nvmcommunity/laravel-eloquent-api
```

See more details about how to use `nvmcommunity/laravel-eloquent-api` package at in the [Laravel Eloquent API Documentation](https://packagist.org/packages/nvmcommunity/laravel-eloquent-api)

Basic usage
-----------

[](#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

[](#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.

```
