Download the PHP package rozbehsharahi/fhp-rest-api without Composer
On this page you can find all versions of the php package rozbehsharahi/fhp-rest-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rozbehsharahi/fhp-rest-api
More information about rozbehsharahi/fhp-rest-api
Files in rozbehsharahi/fhp-rest-api
Package fhp-rest-api
Short Description Super quick setup of a PHP-REST-API without the use of MySQL, Apache, ...
License MIT
Homepage http://github.com/RozbehSharahi/fhp-rest-api
Informations about the package fhp-rest-api
FHP REST API
(Master
)
Description
FHP REST API provides an easy way to setup a JSON FILE based REST API.
There are no dependencies to MySQL or other databases. All files will be stored as json files by default. Still you may also integrate your own way of saving data, by integrating your own controllers, entites and normalizers.
I'm trying really hard to make this very flexible and at the same easy to understand, i hope you enjoy working with this.
Installation
How to
The following index.php is enough to provide PUT, GET, POST, OPTION, DELETE
routes for your application on the /posts
route:
That's it!
How to use entity classes
(Still experimental)
This way of using FHP REST API is still very experimental, so please used this with caution. For instance you have to define fhp property type annotations, though they don't have any impact on the way a property is saved yet.
Your entity class should look like this:
At the moment it does not make any difference which property type you will use. But it is a good preparation for next releases. You will still have to annotate with one of the following annotations:
@Fhp\Rest\PropertyType\StringType
@Fhp\Rest\PropertyType\BooleanType
@Fhp\Rest\PropertyType\IntegerType
Defining custom entity-controllers
You may also define your own controllers to handle model-requests. Just pass
your controller's class name as the third parameter to $api->createModel
.
Please extend Fhp\Rest\Controller
and
feel free to override the basic actions:
public function indexAction($request, $response, $args) {}
public function showAction($request, $response, $args) {}
public function updateAction($request, $response, $args) {}
public function deleteAction($request, $response, $args) {}
public function createAction($request, $response, $args) {}
by calling $api->activateEntity
like following:
Super fast start without Apache
No apache, No MySQL, just make sure PHP is installed on your machine.
Since FHP REST API is super independent you may start your server on almost any machine that supports PHP7+ (in future also PHP5.6+). Not even Apache is needed to get it started. Just change your directory to the projects root and go on with:
Start with Apache
In case you want to start FHP REST API on an apache server, please add
the following .htaccess
file to your project's root where
index.php
is located.
Security issues / CORS
FHP REST API has a set of default-headers that are defined in Fhp\Rest\Api
.
These headers also contain 'Access-Control-Allow-Origin' => '*'
which is
a security issue depending on the project.
Please make sure to configure your own header-settings when going to production.
You may do this by following:
Todos and issues
- PropertyTypes
- Refactoring
All versions of fhp-rest-api with dependencies
icanboogie/inflector Version ^1.4
doctrine/common Version ^2.6
mikey179/vfsstream Version ^1.6
phpunit/phpunit Version 5.7.*