Download the PHP package kingsoft/persist-rest without Composer
On this page you can find all versions of the php package kingsoft/persist-rest. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kingsoft/persist-rest
More information about kingsoft/persist-rest
Files in kingsoft/persist-rest
Package persist-rest
Short Description REST interface for \Kingsoft\Persist classes
License MIT
Informations about the package persist-rest
Kingsoft / Persist REST
This packege uses \Kingsoft\Http, \Kingsoft\PersistDb to expose all the tables and views discoverd by PersistDb discover.php
and of those the ones added to the allowedEndPoints
list. If it is not on that list the api will return a 404
. So
other data is save. A table or view is accessible with, GET, POST, PUT, DELETE reqeests but those can also be restricted using allowedMethods
. The reqeust follow the rfc9205 standard with some extensions.
- POST
https://example.com/resource
will create a new record with the values specifed in the json payload. If the record has autoincrment true a new ID is created and returned (C) - GET
https://example.com/resource
gets a list of all resources restricted bymaxresults
(R) - GET
https://example.com/resource[n,c]
gets a list of resource starting with positionn
and limited byc
. The response will include links for pagination. (R) - GET
https://example.com/resource/<id>
get the record withid
specified (R) - GET
https://example.com/resource?<key>=<value>
gets all the recources where attributekey
=value
. Combine mutliples with&
(R) - GET
https://example.com/resource?<key>=!<value>
gets all the recources where attributekey
!=value
. (R) - GET
https://example.com/resource?<key>=U<value1>,<value2>
gets all the recources where attributekey
IN (value1
,value2
) other operators are avaiable. See \Kingsoft\Persist for those (R) - PUT
https://example.com/resource/<id>
will set new values specifed in the json payload (U) - DELETE
https://example.com/resource/<id>
deletes the resource with theid
specifie (D)
So the interface creates a complete CRUD interface for all resources (tables, views) exposed. Remember however that views can not normally be updated. So make sure your views include the key for the main underlying table. I have not found out a
way to retrieve the underlying tables (on MySQL, MariaDB) so it is currently not possible to automate this
GET results are stored in a resources
object in the json response allongside links and other messages to make a semi level 3.
Pre-flight is handled by observing the OPTION method and returning the proper hints.
Sample usage
It is ofcourse possible to read the constructor parameters from a configuration file.
Add allowedendpoints
Kingsoft persist-db
To create the allowed endpoints with Kingsoft\Persist-db
generate them with
http://example.com/vendor/kingsoft/persist-db/src/discover/
Followed by these steps
- Copy the allowedendpoints settings to the ini file and
- Copy the psr-4 section to
composer.json
. After that make sure to reload the autoloader with
And to use pretty URLs a htacess
nginx configuration by winginx.com
location ~ ^(.*)$ { }
location / { rewrite ^(.*)$ /api/index.php; }
All versions of persist-rest with dependencies
kingsoft/persist Version ^3.0
psr/log Version ^3.0
kingsoft/db Version ^2.7