{"id":15026109,"url":"https://github.com/afgprogrammer/php-mvc-rest-api","last_synced_at":"2025-04-09T20:04:31.998Z","repository":{"id":48776600,"uuid":"138121290","full_name":"afgprogrammer/PHP-MVC-REST-API","owner":"afgprogrammer","description":"A simple PHP MVC REST API framework with PHP 7.2 With routes and some tools to develop your API.","archived":false,"fork":false,"pushed_at":"2021-07-12T17:26:49.000Z","size":53,"stargazers_count":151,"open_issues_count":2,"forks_count":41,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-09T20:04:25.131Z","etag":null,"topics":["api","framework","framework-mvc","framework-php","model-view-controller","mvc","mvc-application","mvc-architecture","mvc-framework","mvc-php","mvc-php-framework","php","php-framework","php-mvc","php72","rest-api","simple-framework"],"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/afgprogrammer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":"afgprogrammer","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2018-06-21T05:00:18.000Z","updated_at":"2025-02-27T11:00:00.000Z","dependencies_parsed_at":"2022-09-17T08:34:44.129Z","dependency_job_id":null,"html_url":"https://github.com/afgprogrammer/PHP-MVC-REST-API","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afgprogrammer%2FPHP-MVC-REST-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afgprogrammer%2FPHP-MVC-REST-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afgprogrammer%2FPHP-MVC-REST-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afgprogrammer%2FPHP-MVC-REST-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/afgprogrammer","download_url":"https://codeload.github.com/afgprogrammer/PHP-MVC-REST-API/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103865,"owners_count":21048245,"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":["api","framework","framework-mvc","framework-php","model-view-controller","mvc","mvc-application","mvc-architecture","mvc-framework","mvc-php","mvc-php-framework","php","php-framework","php-mvc","php72","rest-api","simple-framework"],"created_at":"2024-09-24T20:03:48.350Z","updated_at":"2025-04-09T20:04:31.965Z","avatar_url":"https://github.com/afgprogrammer.png","language":"PHP","readme":"# Guideline for using PHP MVC REST API\n\n\u003ch2\u003e What is REST API? \u003c/h2\u003e\n\u003cp\u003e A REST API (also known as RESTful API) is an application programming interface (API or web API) that conforms to the constraints of REST architectural style and allows for interaction with RESTful web services. REST stands for representational state transfer and was created by computer scientist Roy Fielding.\n\u003cbr\u003e\u003cbr\u003e\nAn API is a set of definitions and protocols for building and integrating application software. It’s sometimes referred to as a contract between an information provider and an information user—establishing the content required from the consumer (the call) and the content required by the producer (the response). For example, the API design for a weather service could specify that the user supply a zip code and that the producer reply with a 2-part answer, the first being the high temperature, and the second being the low.  \u003c/p\u003e\n\n\u003ch1\u003eIntroduction\u003c/h1\u003e\n\u003cp\u003eSimply, the framework will route requests to the correct controller and model. It will do this by analysing request URI for the controller name and the request type (be it POST, PUT, GET, etc.). It will then do some sanity checks, before initialising a new controller and model object and calling the correct method on the controller.\u003c/p\u003e\n\u003ch1\u003eDocumentation\u003c/h1\u003e\n\u003ch2\u003e Add a new route \u003c/h2\u003e\n\u003cp\u003e For creating a new route you should open Route.php file from Router directory.  \u003c/p\u003e\n\u003cp\u003e There is already exist some examples in the file which you can use them as you need.\u003c/p\u003e\n\n```php\n\u003c?php\n\n$router-\u003eget('/home', 'home@index');\n\n$router-\u003epost('/home', 'home@post');\n\n$router-\u003eget('/', function() {\n    echo 'Welcome ';\n});\n```\n\n\u003cp\u003e For getting parameters follow below example: \u003c/p\u003e\n\n```php\n\u003c?php\n\n$router-\u003eget('/:name', function($param) {\n    echo 'Welcome ' . $param['name'];\n});\n```\n\u003cp\u003e For example, when I use this url \"yourdomin.com/afgprogrammer\" I will get following output.\u003c/p\u003e\n\n```\nWelcome afgprogrammer\n```\n\n\u003cp\u003e It's just a Piece of cake :) \u003c/p\u003e\n\u003cp\u003e If you want to send the POST requests follow below example: \u003c/p\u003e\n\n```php\n\n$router-\u003epost('/:name', function($param) {\n    echo 'Welcome ' . $param['name'];\n});\n\n```\n\u003ch2\u003e Database Connection \u003c/h2\u003e\n\n\u003e \u003cp\u003e Consider that for using database you should edit config.php file before start using database.\u003c/p\u003e\n\n\u003cp\u003e For getting a database connection, you can use below sample in Model directory: \u003c/p\u003e\n\n```php\n\u003c?php\n\nuse MVC\\Model;\n\nclass ModelsHome extends Model {\n\n    public function getAllUser() {\n        $query = $this-\u003edb-\u003equery(\"SELECT * FROM \" . DB_PREFIX . \"user\");\n        \n        /*\n          $query-\u003erow : return 1 row\n          $query-\u003erows : return all rows\n          $query-\u003enum_rows : return rows count\n        */\n        return $query-\u003erows;\n    }\n}\n```\n","funding_links":["https://patreon.com/afgprogrammer"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafgprogrammer%2Fphp-mvc-rest-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fafgprogrammer%2Fphp-mvc-rest-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafgprogrammer%2Fphp-mvc-rest-api/lists"}