Skip to content

PHP simple CRUD REST API based on file document store - no dependencies

Notifications You must be signed in to change notification settings

kvdmolen/onefileapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Onefileapi

A simple CRUD REST API based on file document store for PHP. No dependencies.

No database required, all data is stored in one single JSON file.

Usage

$router->get("/products", function($response, $body, $args){
	$response->success($response->all("products"), "myProducts");
});

Then GET '/index.php/products' results in

{
	success: true,
	data: {
		myProducts: [
			{
				"id":"5c030fef1cd75",
				"name":"Product 1"
			},{
				"id":"5c043c2131fc5",
				"name":"Product 2"
			}
		]
	}
}
$router->get("/products/:id", function($response, $body, $args){
	$response->success($response->one("products"), $args["id"], "myProduct");
});

Then GET '/index.php/products/5c030fef1cd75' results in

{
	success: true,
	data: {
		myProduct: {
			"id":"5c030fef1cd75",
			"name":"Product 1"
		}
	}
}

Also, GET '/index.php/products/invalidid' results in HTTP Response code 400 and

{
	success: false,
	message: "Item not found"
}

See index.php for POST, PUT and DELETE examples.

Permissions

Make sure to set correct permissions on both index.php and store.json.

Disclaimer

Not intended for large datasets, nor for production webapps. Intended to quickly pull up a fully functional REST API.

About

PHP simple CRUD REST API based on file document store - no dependencies

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages