A simple PHP REST API to access data stored in the filesystem
This is an extremely lightweight REST API that utilizes (JSON) files as data stores. Just name your stores and point them to a file, and snAPI-File will handle the rest.
If you run into any problems, please let us know by opening a new issue.
You must point snAPI-File to the stores you want to use. By default, snAPI-File loads those from a stores.json
file, however you may change that through the constructor (see below).
The store file should be in the following format.
{
"store1": "store1.json",
"store2": "store2.json"
}
The store being used is sent in each request. Only stores referenced in the store file are supported. Any other referenced store will result in an HTTP 404 error.
Setting up the API is simple. Just create your store file and add the following lines to your PHP file.
use \SnapiFile\Api;
$api = new Api();
$api->go();
That's it. snAPI-File will handle the requests from there.
Parameter | Type | Required | Default | Notes |
---|---|---|---|---|
$storeFile |
string | 'stores.json' |
The default file is created in the same directory as your PHP file. |
Type | Notes |
---|---|
Api |
The Api object |
Parameter | Type | Required | Default | Notes |
---|---|---|---|---|
void |
Type | Notes |
---|---|
void |
Requests to snAPI-File must be either GET
or POST
and include a specific set of parameters.
Parameter | Required | Notes |
---|---|---|
store | ✔️ | The store to use |
action | ✔️ | The action to perform (i.e., create , retrieve , update , delete ) |
key | The key in the store to affect Only required for create , update , and delete actions. Use with retrieve to get a specific record from the store. Omit from retrieve to get all records from the store. |
|
value | ✔️ | The value to use to affect key |