Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jalbam/fake_rest_server

[REST server in PHP] Simple and easy-to-configure REST server made in PHP.
https://github.com/jalbam/fake_rest_server

configurable cross-device cross-platform easy-to-use fake-services multiplatform php rest rest-api rest-microservice rest-server restapi restful restful-api server server-backend service simple testing testing-tools

Last synced: 2 months ago
JSON representation

[REST server in PHP] Simple and easy-to-configure REST server made in PHP.

Awesome Lists containing this project

README

        

REST server in PHP
===================
by [Joan Alba Maldonado](https://joanalbamaldonado.com/) (joanalbamaldonadoNO_SPAM_PLEASE AT gmail DOT com, without NO_SPAM_PLEASE)

Simple and easy-to-configure REST server made in PHP.

Version: no version
- Date: 12th May 2016 (approximately)

## Description

Simple and easy-to-configure REST server made in PHP.

I made it just to create different REST servers very fast for testing purposes.

## Configuring the server

To add new paths (routes) and methods, the developer just needs to create a new folder structure (folder and subfolders if needed) which represents the route and inside one file per method named _[method_desired].php_ (for example, _put.php_).

To start developing your REST server, you will only need to download the files inside the **[src/](src/)** folder.

You may want to take a look at the **[src/_code/functions.php](src/_code/functions.php)** file (the engine will include it automatically) as it provides some basic but useful functions. There you can also add new functions or modify the existing ones.

If you want to add data, you can use the **[src/_code/data/data.php](src/_code/data/data.php)** file (automatically included by the engine).

If you want to add configuration data, you can use the **[src/_code/config.php](src/_code/config.php)** file (automatically included by the engine).

As the engine defines the **USING_REST_SERVER** constant, you can protect any of the files with the following line at the beginning:
```php

```

Note: this authorization code above is also defined in the **AUTHORIZATION_CODE** constant (inside the the **[src/_code/config.php](src/_code/config.php)** file).


### Example:

1) In the root folder (where the **[src/_code/](src/_code/)** folder and the **[src/index.php](src/index.php)** file are placed), create a folder called **myRESTService/**.

2) Inside the **myRESTService/** folder we have just created, create another folder called **user/** and inside of it create two files: **index.php** and **get.php**.

3) Inside the **myRESTService/user/index.php** file, place the following code:
```php

Array
(
"name" => "John Doe",
"favouriteFood" => "meat"
),
"2" =>
Array
(
"name" => "Joan Alba Maldonado",
"favouriteFood" => "pizza"
)
);

//Gets the data needed which has been sent through the REST client:
$userId = getVariable("id"); //"getVariable" and other functions available in the "src/_code/functions.php" file.
```

4) Inside the **myRESTService/user/get.php** file put the following code:
```php