{"id":21197056,"url":"https://github.com/jalbam/fake_rest_server","last_synced_at":"2025-07-10T05:31:23.925Z","repository":{"id":56996032,"uuid":"65598853","full_name":"jalbam/fake_rest_server","owner":"jalbam","description":"[REST server in PHP] Simple and easy-to-configure REST server made in PHP.","archived":false,"fork":false,"pushed_at":"2020-01-24T07:32:28.000Z","size":25,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T11:01:35.580Z","etag":null,"topics":["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"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jalbam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-13T04:17:36.000Z","updated_at":"2024-02-22T15:18:42.000Z","dependencies_parsed_at":"2022-08-21T11:10:13.128Z","dependency_job_id":null,"html_url":"https://github.com/jalbam/fake_rest_server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jalbam/fake_rest_server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jalbam%2Ffake_rest_server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jalbam%2Ffake_rest_server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jalbam%2Ffake_rest_server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jalbam%2Ffake_rest_server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jalbam","download_url":"https://codeload.github.com/jalbam/fake_rest_server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jalbam%2Ffake_rest_server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264535993,"owners_count":23624404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["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"],"created_at":"2024-11-20T19:42:27.977Z","updated_at":"2025-07-10T05:31:23.629Z","avatar_url":"https://github.com/jalbam.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"REST server in PHP \n=================== \nby [Joan Alba Maldonado](https://joanalbamaldonado.com/) (joanalbamaldonadoNO_SPAM_PLEASE AT gmail DOT com, without NO_SPAM_PLEASE)\n\nSimple and easy-to-configure REST server made in PHP.\n\nVersion: no version \n- Date: 12th May 2016 (approximately)\n\n\n## Description\n\nSimple and easy-to-configure REST server made in PHP.\n\nI made it just to create different REST servers very fast for testing purposes.\n\n\n## Configuring the server\n\nTo 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_).\n\nTo start developing your REST server, you will only need to download the files inside the **[src/](src/)** folder.\n\nYou 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.\n\nIf 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).\n\nIf you want to add configuration data, you can use the **[src/_code/config.php](src/_code/config.php)** file (automatically included by the engine).\n\nAs the engine defines the **USING_REST_SERVER** constant, you can protect any of the files with the following line at the beginning:\n```php\n\u003c?php if (!defined(\"USING_REST_SERVER\") || !USING_REST_SERVER) { return; } ?\u003e\n```\n\nNote: this authorization code above is also defined in the **AUTHORIZATION_CODE** constant (inside the the **[src/_code/config.php](src/_code/config.php)** file).\n\n\n\u003ca name=\"example\"\u003e\u003c/a\u003e\n### Example:\n\n1) 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/**.\n\n2) 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**.\n\n3) Inside the **myRESTService/user/index.php** file, place the following code:\n```php\n\u003c?php\n\t//Users info (this could be in the \"src/_code/config.php\" file, but it is just an example):\n\t$usersData = Array\n\t(\n\t\t//User IDs:\n\t\t\"1\" =\u003e\n\t\t\tArray\n\t\t\t(\n\t\t\t\t\"name\" =\u003e \"John Doe\",\n\t\t\t\t\"favouriteFood\" =\u003e \"meat\"\n\t\t\t),\n\t\t\"2\" =\u003e\n\t\t\tArray\n\t\t\t(\n\t\t\t\t\"name\" =\u003e \"Joan Alba Maldonado\",\n\t\t\t\t\"favouriteFood\" =\u003e \"pizza\"\n\t\t\t)\n\t);\n\t\n\t//Gets the data needed which has been sent through the REST client:\n\t$userId = getVariable(\"id\"); //\"getVariable\" and other functions available in the \"src/_code/functions.php\" file.\n```\n\n4) Inside the **myRESTService/user/get.php** file put the following code:\n```php\n\u003c?php\n\tif ($userId === \"\") { echo \"No id sent!\"; }\n\telse if (array_key_exists($userId, $usersData))\n\t{\n\t\techo $usersData[$userId][\"name\"] . \" likes eating \" . $usersData[$userId][\"favouriteFood\"];\n\t}\n\telse { echo \"User cannot be found! (id=\" . $userId . \")\"; }\n```\n\n5) With this, we will have our REST server configured with the **myRESTService/user/** route, accepting the **GET** method with the **id** parameter. This example can be found in the **[example_easy/](example_easy/)** folder.\n\n\n## Testing the server\n\nIf you do not have a REST client, the server can be tested on any web browser by adding the **debug=1** parameter to the URL as well as the **method** parameter with the method desired (not needed if the method is **GET**), as for example: http://localhost/fake_rest_server/src/index.php/route_1/subroute?method=post\u0026debug=1\u0026username=Joan\n\nFollowing the [example above](#example), you can use a web browser to visit the following links:\n\nhttp://localhost/route_to_the_REST_server/index.php/myRESTService/user/?method=get\u0026debug=1\u0026id=1 (it should show \"John Doe likes eating meat\")\n\nhttp://localhost/route_to_the_REST_server/index.php/myRESTService/user/?method=get\u0026debug=1\u0026id=2 (it should show \"Joan Alba Maldonado likes eating pizza\")\n\nhttp://localhost/route_to_the_REST_server/index.php/myRESTService/user/?method=get\u0026debug=1\u0026id=3 (it should show \"User cannot be found! (id=3)\")\n\nhttp://localhost/route_to_the_REST_server/index.php/myRESTService/user/?method=get\u0026debug=1 (it should show \"No id sent!\")\n\nNote that the \"_/_\" character at the end of the route is optional.\n\n\n## Final comments\n\nIt is very easy to extend using PHP language. The project already includes some examples with routes, methods, functions and data as user accounts, etc. as examples (in both the **[example/](example/)** and the **[example_easy/](example_easy/)** folder) but they can be deleted.\n\nThe only really-needed code is located in the **[src/](src/)** folder. Inside of it, the **[route_1/](src/route_1/)** folder and all of its content can also be deleted since it is just an example.\n\n\n## License\nThis project can be used, reproduced, distributed and modified freely for any non-commercial purposes but always keeping the author's name and copyright clauses. Other than that, just use this project as you wish but never sell it!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjalbam%2Ffake_rest_server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjalbam%2Ffake_rest_server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjalbam%2Ffake_rest_server/lists"}