{"id":15023291,"url":"https://github.com/indigomultimediateam/php_rest_api","last_synced_at":"2026-02-11T01:34:56.589Z","repository":{"id":44000748,"uuid":"509532950","full_name":"IndigoMultimediaTeam/php_rest_api","owner":"IndigoMultimediaTeam","description":"A generic way to implement (REST) API for PHP ≥5.2","archived":false,"fork":false,"pushed_at":"2024-11-29T14:26:30.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-13T01:15:08.837Z","etag":null,"topics":["api","php","php52","rest-api"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IndigoMultimediaTeam.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-01T17:11:35.000Z","updated_at":"2024-11-29T14:26:34.000Z","dependencies_parsed_at":"2025-03-13T01:12:37.306Z","dependency_job_id":"80298bf6-19b4-4708-986b-39d54a646ada","html_url":"https://github.com/IndigoMultimediaTeam/php_rest_api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/IndigoMultimediaTeam/php_rest_api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndigoMultimediaTeam%2Fphp_rest_api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndigoMultimediaTeam%2Fphp_rest_api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndigoMultimediaTeam%2Fphp_rest_api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndigoMultimediaTeam%2Fphp_rest_api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IndigoMultimediaTeam","download_url":"https://codeload.github.com/IndigoMultimediaTeam/php_rest_api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndigoMultimediaTeam%2Fphp_rest_api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269976794,"owners_count":24506467,"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","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["api","php","php52","rest-api"],"created_at":"2024-09-24T19:58:55.125Z","updated_at":"2026-02-11T01:34:56.563Z","avatar_url":"https://github.com/IndigoMultimediaTeam.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![LTS+sub-branches](https://img.shields.io/badge/submodule-LTS+sub--branches-informational?style=flat-square\u0026logo=git)](https://github.com/IndigoMultimediaTeam/lts-driven-git-submodules)\n# PHP REST API\nActually, this repository provides a generic way to implement API (so not only REST API). *Tested/used in PHP \u003c5.3*.\nThe expected directory structure is:\n```\napi/\n\tthis_repo/\n\t_config.php … see below\n\tindex.php … or any other entry php file\n\t.htaccess\n```\nThe API entry is splitted into several steps:\n1. config … see [AbstractConfig.php](./AbstractConfig.php)\n1. request processing … see for exmaple [RequestHTTP.php](./RequestHTTP.php), [RequestServer.php](./RequestServer.php)\n1. special cases … see for exmaple [AuthorizationJWT.php](./AuthorizationJWT.php), [HelpREST](./HelpREST.php)\n1. the actual processing of the request … see [apiREST.php](./apiREST.php)\n1. response … see for example [ResponseJSON](./ResponseJSON.php)\n\n## Use in your repo\n**Use**:\n```bash\ncd TARGET_PATH\ngit submodule add -b main --depth=1 git@github.com:IndigoMultimediaTeam/php_rest_api _internal\n```\n… more info [`git submodule`](https://gist.github.com/jaandrle/b4836d72b63a3eefc6126d94c683e5b3).\n\n*Target folder (`_internal`) schouldn’t be accessible from outside of the web!*\n\n## Minimal REST API example whith authentication\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003e\u0026lowbar;config.php\u003c/b\u003e\u003c/summary\u003e\n\n```php\n\u003c?php\n/* import { AbstractConfig } from */require_once '_internal/AbstractConfig.php';\nclass config extends AbstractConfig{\n\tpublic $secret= 'secret for authentication/authorization';\n\t/** Result of authentication */\n\tpublic $client;\n\tpublic $versions= array(\n\t\t'warty-warthog',\n\t\t'hoary-hedgehog',\n\t\t'dapper-drake'\n\t);\n}\n```\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eindex.php\u003c/b\u003e\u003c/summary\u003e\n\n```php\n\u003c?php\nrequire_once '../../kernel/kernel.php';//fix path\nrequire_once '../utils/inc.db_utils.php';//fix path\n/* import { Config } from */require_once '_config.php';\n$config= new config();\n$config-\u003eapi_url= 'https://'.$_SERVER['HTTP_HOST'].'/api/rest';\n/* import { Request } */require_once '_internal/RequestHTTP.php';\n$request= new Request($config);\n// api logging if needed, see later\n/* import { Response } */require_once '_internal/ResponseJSON.php';\n$response= new Response($request);\n// special help endpoints, see later\n/* import { Authorization } */require_once '_internal/AuthorizationJWT.php';\n$auth= new Authorization($config, $request, $response);\n$config-\u003eclient= $auth-\u003ejwt_playload;\n\n/* import { api } */require_once '_internal/apiREST.php';\n$response-\u003ephase('[2] Request processing');\n\t\t\t\t\t try{\t return $response-\u003esuccess(api($config, $request)); }\ncatch(\\Exception $error){\t return $response-\u003eerror($error); }\n```\n\u003c/details\u003e\n\n… for authorization via [AuthorizationJWT.php](./AuthorizationJWT.php) you need to provide *auth* folder (see `AbstractConfig-\u003e$auth_path`):\n\n```\napi/\n\tthis_repo/\n\t…\n\tauth/\n\t\ttoken/\n\t\t\tpost.php\n\t\tauthorize/\n\t\t\tpost.php\n\t\tupdate/\n\t\t\tpost.php\n```\n… this is similar to REST API handlering via [apiREST](./apiREST.php).\n\nThe folder structure follows the requested URL:\n```\nhttps://api_url/api_version/Folder/…\n\nfolder:\napi/\n\tthis_repo/\n\tFolder/…\n```\n…request method indicates which file to use:\n```\ncurl -X POST https://api_url/api_version/Folder\n\nfile:\nfolder:\napi/\n\tthis_repo/\n\tFolder/post.php\n```\n\nFor more extended version visits [DHLC-Internet-Networking/web/api/rest at dev/php_rest_api · jaandrle/DHLC-Internet-Networking](https://github.com/jaandrle/DHLC-Internet-Networking/tree/dev/php_rest_api/web/api/rest).\n\n\n## Minimal version of making API accessible from inside the server\n```php\n\u003c?php\n/**\n * @param string $get Target URL `version/target`\n * @param \"get\"|\"delete\"|\"put\"|\"post\" $method\n * @param array\u003cstring, mixed\u003e $body\n * */\nfunction api($get, $method= 'get', $body= array()){\n\t$cwd= $GLOBALS['__dROOT'].'api/rest/';\n\trequire_once $cwd.'_internal/libs/globals.php';\n\t/* import { Config } from */require_once $cwd.'_config.php';\n\t$config= new config();\n\t$config-\u003eapi_url= 'https://'.$_SERVER['HTTP_HOST'].'/api/rest';\n\t/* import { Request } */require_once $cwd.'_internal/RequestServer.php';\n\t$request= new Request($config, $get, $method, $body);\n\textract($config-\u003evars_shared);\n\t\n\t$folder= $cwd.$request-\u003etargetPath();\n\t$path= realpath($folder);\n\tif($path===false||!is_dir($path)) throw new \\Exception(\"Endpoint '$folder' doesn’t exist.\", 404);\n\t$file= $path.'/'.$request-\u003emethod.'.php';\n\tif(file_exists($file)) return require_once $file;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findigomultimediateam%2Fphp_rest_api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Findigomultimediateam%2Fphp_rest_api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findigomultimediateam%2Fphp_rest_api/lists"}