{"id":16776036,"url":"https://github.com/esbenp/larapi","last_synced_at":"2025-04-06T04:12:05.778Z","repository":{"id":43012556,"uuid":"56343756","full_name":"esbenp/larapi","owner":"esbenp","description":"An API-friendly fork of Laravel. Authentication, error handling, resource filtering, sorting, pagination and much more included","archived":false,"fork":false,"pushed_at":"2022-03-23T15:46:36.000Z","size":81,"stargazers_count":403,"open_issues_count":27,"forks_count":113,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-03-30T03:05:42.356Z","etag":null,"topics":["api","framework","laravel","laravel-api","php","php-api","rest-api"],"latest_commit_sha":null,"homepage":"http://esbenp.github.io/2016/04/11/modern-rest-api-laravel-part-0/","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/esbenp.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-15T19:10:49.000Z","updated_at":"2025-03-11T18:22:13.000Z","dependencies_parsed_at":"2022-09-13T09:50:48.556Z","dependency_job_id":null,"html_url":"https://github.com/esbenp/larapi","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/esbenp%2Flarapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esbenp%2Flarapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esbenp%2Flarapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esbenp%2Flarapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/esbenp","download_url":"https://codeload.github.com/esbenp/larapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430872,"owners_count":20937874,"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","laravel","laravel-api","php","php-api","rest-api"],"created_at":"2024-10-13T07:08:47.845Z","updated_at":"2025-04-06T04:12:05.737Z","avatar_url":"https://github.com/esbenp.png","language":"PHP","readme":"# Larapi\n\nLarapi is an API-friendly fork of Laravel, batteries included. If you want to read a more in-depth description \nof the offerings and how to do modern API development in Laravel I have written a series of blogposts on the topic.\n\n[A Modern REST API in Laravel 5](http://esbenp.github.io/2016/04/11/modern-rest-api-laravel-part-0/)\n\nLarapi comes included with...\n* Laravel 5.4\n* Laravel Passport for OAuth Authentication, including a proxy for password and refresh-token grants\n* A new directory structure optimized for separating infrastructure and domain code. Groups your controllers, models, etc. by resource-type. \n[Read more and view the source code here](https://github.com/esbenp/distributed-laravel)\n* [Optimus\\Heimdal](https://github.com/esbenp/heimdal): A modern exception handler for APIs with Sentry and Bugsnag integration out-of-the-box\n* [Optimus\\Bruno](https://github.com/esbenp/bruno): A base controller class that gives sorting, filtering, eager loading and pagination for your endpoints\n* [Optimus\\Genie](https://github.com/esbenp/genie): A base repository class for requesting entities from your database. Includes integration with Bruno.\n* [Optimus\\Architect](https://github.com/esbenp/architect): A library for creating advanced structures of related entities\n* [Optimus\\ApiConsumer](https://github.com/esbenp/laravel-api-consumer): A small class for making internal API requests \n\n## Motivation\n\nWe maintain a fairly large Laravel API at [Traede](https://traede.com). Our philosophy is to utilize the framework as much as possible. \nHowever, we also strongly feel that the amount of people that use Laravel for API development is not as large as it could be. \nWe *feel* that Laravel as a framework tries to focus more on traditional web development (i.e. rendering HTML). We try to modify the framework \njust a little bit so it is more suited for API development. Larapi is the result of the changes we have made at Traede in order \nto make Laravel more enjoyable as an API framework.\n\n## Installation \n\nFirst clone the repository\n\n```bash\ngit clone https://github.com/esbenp/larapi my-api\n```\n\nInstall dependencies\n\n```bash\ncomposer install\n```\n\nCopy the `.env` file an create an application key\n\n```\ncp .env.example .env \u0026\u0026 php artisan key:generate\n```\n\nMigrate the tables.\n\n```\nphp artisan migrate\n```\n\nLarapi comes with Passport include as the default authenticatin method. You should now install it using this command.\n\n```\nphp artisan passport:install\n```\n\nCopy-paste the generated secrets and IDs into your `.env` file like so.\n\n```\nPERSONAL_CLIENT_ID=1\nPERSONAL_CLIENT_SECRET=mR7k7ITv4f7DJqkwtfEOythkUAsy4GJ622hPkxe6\nPASSWORD_CLIENT_ID=2\nPASSWORD_CLIENT_SECRET=FJWQRS3PQj6atM6fz5f6AtDboo59toGplcuUYrKL\n```\n\nIf you want to save it elsewhere or change the naming be sure to modify the LoginProxy in `infrastructure/Auth/LoginProxy.php`\n\n## Test installation\n\nYou can quickly test if the authentication works by creating an user using the include command.\n\n```bash\nphp artisan users:add Esben esben@esben.dk 1234\n```\n\nNow serve your application and try to request a token using cURL\n\n```bash\nphp artisan serve\ncurl -X POST http://localhost:8000/login -H 'Content-Type:application/json' -d '\n{\n    \"email\":\"esben@esben.dk\",\n    \"password\":\"1234\"\n}'\n```\n\nThis should return a token.\n\n```json\n{\"access_token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImM0MWZiOWFjZjkyZmRiY2RhYjE0ZmEwYTFlMzMwYjBjYTEwMmRiMTA1ZGI4MmZjYzllZGUwMjRiNzI2MjA2YjRhZDU4MGZhMjUxODU2Y2RkIn0.eyJhdWQiOiIyIiwianRpIjoiYzQxZmI5YWNmOTJmZGJjZGFiMTRmYTBhMWUzMzBiMGNhMTAyZGIxMDVkYjgyZmNjOWVkZTAyNGI3MjYyMDZiNGFkNTgwZmEyNTE4NTZjZGQiLCJpYXQiOjE0ODk5NTM3MDYsIm5iZiI6MTQ4OTk1MzcwNiwiZXhwIjoxNDg5OTU0MzA2LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.SmsEyCEXBiwSgl0yMcjvCxoZ2a_7D6GDJTxTs_J-6yzUeJkOofrSV7RRafO3VvUckrNqy5sGgglrwGH_HN7_lNPU6XcgaaNzbzf-g7vCSzCicJiYZVzxqJpZVwqQ4WIQrc0lYdk7suZ7hwQulOD_Z79JhBNh1KSAyo3ABWHiRjh9NR_-iAjvlCohh7nAETDeVqoMrR99m3fwQYOjdtvRBHJ8Ei-Kx3Gn1DyOXyh8eGa5-yDtj-ZVI9x66YMXlm8wk4IMA_Oh7KJISfdpoQs4fPyrGsFAxQMFp02qEW2fzKl2eesZeiIAyDGWE4StHsuY3E4jZL0P-pjv08j5W4CBP0P64gkNw_GdbxlPPA-qZUzJlc3EtjrzZ9WZq3JAKKCGy5I1jHECDOqaQ1z7axm6rmxRWmXmRGwwkne8QxfPlXsN0sm5q98mJckeqCLUuir1VPyFn5Z-B7D80-sc7Zm-7zi-awJtZUGMcHSo_yNHXjVGcbJwFk04xoIL2QzMXpOVPLaUdlBp_obCJhdzT5Bx0o5SDdK2LwgEwbMkksqmrTJ7ypoezsc3ihVQIrMelK2lNfkH_cDcVdD3ub8oFTthbA62U6atXaIADcsgTCgOtgQ2uXTIko_btjECgL35LZDd8UxiyQT3w-pDrELGDPx17DQCsIZDJ8mC1s6E0d7EPsA\",\"expires_in\":600}\n```\n\nNow try to request all users `GET /users` using the newly issued token.\n\n```bash\ncurl http://localhost:8000/users -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImM0MWZiOWFjZjkyZmRiY2RhYjE0ZmEwYTFlMzMwYjBjYTEwMmRiMTA1ZGI4MmZjYzllZGUwMjRiNzI2MjA2YjRhZDU4MGZhMjUxODU2Y2RkIn0.eyJhdWQiOiIyIiwianRpIjoiYzQxZmI5YWNmOTJmZGJjZGFiMTRmYTBhMWUzMzBiMGNhMTAyZGIxMDVkYjgyZmNjOWVkZTAyNGI3MjYyMDZiNGFkNTgwZmEyNTE4NTZjZGQiLCJpYXQiOjE0ODk5NTM3MDYsIm5iZiI6MTQ4OTk1MzcwNiwiZXhwIjoxNDg5OTU0MzA2LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.SmsEyCEXBiwSgl0yMcjvCxoZ2a_7D6GDJTxTs_J-6yzUeJkOofrSV7RRafO3VvUckrNqy5sGgglrwGH_HN7_lNPU6XcgaaNzbzf-g7vCSzCicJiYZVzxqJpZVwqQ4WIQrc0lYdk7suZ7hwQulOD_Z79JhBNh1KSAyo3ABWHiRjh9NR_-iAjvlCohh7nAETDeVqoMrR99m3fwQYOjdtvRBHJ8Ei-Kx3Gn1DyOXyh8eGa5-yDtj-ZVI9x66YMXlm8wk4IMA_Oh7KJISfdpoQs4fPyrGsFAxQMFp02qEW2fzKl2eesZeiIAyDGWE4StHsuY3E4jZL0P-pjv08j5W4CBP0P64gkNw_GdbxlPPA-qZUzJlc3EtjrzZ9WZq3JAKKCGy5I1jHECDOqaQ1z7axm6rmxRWmXmRGwwkne8QxfPlXsN0sm5q98mJckeqCLUuir1VPyFn5Z-B7D80-sc7Zm-7zi-awJtZUGMcHSo_yNHXjVGcbJwFk04xoIL2QzMXpOVPLaUdlBp_obCJhdzT5Bx0o5SDdK2LwgEwbMkksqmrTJ7ypoezsc3ihVQIrMelK2lNfkH_cDcVdD3ub8oFTthbA62U6atXaIADcsgTCgOtgQ2uXTIko_btjECgL35LZDd8UxiyQT3w-pDrELGDPx17DQCsIZDJ8mC1s6E0d7EPsA'\n```\n\nThis should return a response like so\n\n```json\n{\"users\":[{\"id\":1,\"name\":\"Esben\",\"email\":\"esben@esben.dk\",\"created_at\":\"2017-03-19 19:59:15\",\"updated_at\":\"2017-03-19 19:59:15\"}]}\n```\n\nYou can refresh a new token by requesting `POST /login/refresh` and logout using `POST /logout`\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/esbenp/architect/blob/master/CONTRIBUTING.md) for details.\n\n## License\n\nThe MIT License (MIT). Please see [License File](https://github.com/esbenp/architect/blob/master/LICENSE) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesbenp%2Flarapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fesbenp%2Flarapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesbenp%2Flarapi/lists"}