![]() |
10 роки тому | |
---|---|---|
README.md | 10 роки тому | |
api.php | 10 роки тому |
Simple PHP script that adds a very basic API to a MySQL database
$config = array(
"hostname"=>"localhost",
"username"=>"root",
"password"=>"root",
"database"=>"blog",
"whitelist"=>false,
"blacklist"=>array("users"=>"crudl"),
);
You can do all CRUD (Create, Read, Update, Delete) operations and extra List operation. Here is how:
GET http://localhost/api/categories
GET http://localhost/api/categories,users
GET http://localhost/api/cate*
GET http://localhost/api/cate*,user*
{"categories":{"columns":["id","name"],"records":[["1","Internet"],["3","Web development"]]}}
GET http://localhost/api/categories?page=1
GET http://localhost/api/categories?page=1,50
{"categories":{"columns":["id","name"],"records":[["1","Internet"],["3","Web development"]],"results":2}}
Match types supported:
GET http://localhost/api/categories?filter=name:Inter
GET http://localhost/api/categories?filter=name:Internet&match=exact
GET http://localhost/api/categories?filter=id:1&match=upto
GET http://localhost/api/categories?filter=id:2&match=lower
{"categories":{"columns":["id","name"],"records":[["1","Internet"]]}}
POST http://localhost/api/categories
{"id":"1","name":"Internet"}
1
GET http://localhost/api/categories/1
{"id":"1","name":"Internet"}
PUT http://localhost/api/categories/2
{"id":"1","name":"Internet networking"}
1
DELETE http://localhost/api/categories/2
1
Put the files in a folder named “api” and edit config.php.dist and rename it to config.php. Let Apache serve the parent folder or configure the .htaccess RewriteBase to match the exposed part of the path.
MIT