{"id":24714434,"url":"https://github.com/ml-opensource/rest-api-server","last_synced_at":"2025-10-09T12:31:36.938Z","repository":{"id":56982761,"uuid":"62837494","full_name":"ml-opensource/rest-api-server","owner":"ml-opensource","description":"A framework for rapid REST API development.","archived":false,"fork":false,"pushed_at":"2022-10-21T18:51:04.000Z","size":380,"stargazers_count":6,"open_issues_count":2,"forks_count":2,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-12-11T15:49:30.106Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ml-opensource.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-07T20:53:52.000Z","updated_at":"2024-05-02T06:42:32.000Z","dependencies_parsed_at":"2022-08-21T12:20:16.019Z","dependency_job_id":null,"html_url":"https://github.com/ml-opensource/rest-api-server","commit_stats":null,"previous_names":["ml-opensource/rest-api-server"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ml-opensource%2Frest-api-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ml-opensource%2Frest-api-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ml-opensource%2Frest-api-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ml-opensource%2Frest-api-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ml-opensource","download_url":"https://codeload.github.com/ml-opensource/rest-api-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235820061,"owners_count":19050101,"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":[],"created_at":"2025-01-27T08:16:35.392Z","updated_at":"2025-10-09T12:31:31.588Z","avatar_url":"https://github.com/ml-opensource.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Laravel API Server [![Slack Status](https://fuzz-opensource.herokuapp.com/badge.svg)](https://fuzz-opensource.herokuapp.com/)\n==================\n\nA framework for rapid REST API development.\n\n### Installation\n1. Require the repository in your `composer.json`\n1. Add the `ApiServerServiceProvider` to your application and publish its config `artisan vendor:publish --provider=\"Fuzz\\ApiServer\\Providers\\ApiServerServiceProvider\"`.\n1. Extend the packaged route provider for your app:\n\n```\n    \u003c?php\n    \n    namespace MyApp\\Providers;\n    \n    use Fuzz\\ApiServer\\Providers\\RouteServiceProvider as ServiceProvider;\n    \n    class RouteServiceProvider extends ServiceProvider\n    {\n        // ...\n    }\n```\n1. Extend the packaged exception handler for your app:\n\n```\n    \u003c?php\n    \n    namespace MyApp\\Exceptions;\n    \n    use Fuzz\\ApiServer\\Exception\\Handler as ExceptionHandler;\n    \n    class Handler extends ExceptionHandler\n    {\n        // ...\n    }\n```\n\n## Usage\n### Basic usage\n\nRegister a base controller extending Fuzz\\ApiServer\\Routing\\Controller:\n\n```\n    \u003c?php\n    \n    class MyBaseController extends Fuzz\\ApiServer\\Routing\\Controller {}\n```\nRegister routes pointing to extensions of your base controller. Make a catch-all route to send all other requests through your base controller.\n\n```\n    \u003c?php\n    \n    class MySpecificController extends MyBaseController\n    {\n        public function someEndpoint() {\n            return $this-\u003esucceed('Foobar!');\n        }\n    }\n    \n    Route::get('some-endpoint', 'MySpecificController@someEndpoint');\n    // ...\n    Route::controller(null, 'MyBaseController');\n```\n### ResourceControllers\nResource controllers extend functionality of `fuzz/magic-box` repositories and provide CRUD and authorization functionality out of the box.\n\nYour application should extend the base `fuzz/api-server` Resource controller:\n\n```\n\u003c?php\n\nnamespace MyApp\\Http\\Controllers;\n\nuse Fuzz\\ApiServer\\Routing\\ResourceController as BaseResourceController;\n\nclass ResourceController extends BaseResourceController\n{\n\t// ...\n}\n\n```\n\nAnd to define a route for a resource in your `routes.php`: `$router-\u003erestful('User');`. The `restful` route macro is defined in `Fuzz\\ApiServer\\Providers\\RouteServiceProvider`.\n\n\nIf any resources need to override the default functionality, you can create a specific ResourceController by extending your application's base ResourceController:\n\n`app/Http/Controllers/Resources/Users.php`:\n\n```\n\u003c?php\n\nnamespace MyApp\\Http\\Controllers\\Resources;\n\nuse Illuminate\\Http\\Request;\nuse Fuzz\\MagicBox\\Contracts\\Repository;\nuse MyApp\\Http\\Controllers\\ResourceController;\n\nclass Users extends ResourceController\n{\n\tpublic function index(Repository $repository, Request $request)\n\t{\n\t\t// custom index...\n\t{\n}\n\n```\n\nYou can then point your restful route to your custom ResourceController:\n in `routes.php`: `$router-\u003erestful('Run', 'Resources\\Users');`\n\n### Returning that sweet, sweet, data\nSend mixed data:\n\n```\n    \u003c?php\n    \n    return $this-\u003esucceed(['foo' =\u003e 'bar']);\n```\nSend any arrayable data:\n\n```\n    \u003c?php\n    \n    return $this-\u003esucceed(Model::all());\n```\nSend any paginated data:\n\n```\n    \u003c?php\n    \n    return $this-\u003esucceed(Model::paginate($this-\u003egetPerPage(Model::DEFAULT_PER_PAGE)));\n```\nSend RESTful errors with error codes and optional data:\n\n```\n    \u003c?php\n    \n    $this-\u003ebadRequest('That button does not do what you think it does.');\n    $this-\u003eforbidden('Maybe next time.');\n    $this-\u003enotFound();\n```\nRaise RESTful error exceptions outside of the controller context:\n\n```\n    \u003c?php\n    \n\tthrow new Symfony\\Component\\HttpKernel\\Exception\\ConflictHttpException;\n\tthrow new Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException;\n\tthrow new Symfony\\Component\\HttpKernel\\Exception\\BadRequestHttpException;\n\tthrow new Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException;\n```\nRequire the user to provide certain parameters:\n\n```\n    \u003c?php\n\n    // Magically works with either JSON or form data\n    list($foo, $bar) = $this-\u003erequireParameters('foo', 'bar');\n```\nRead a list of certain parameters:\n\n```\n    \u003c?php\n    \n    list($foo, $bar) = $this-\u003esuggestParameters('foo', 'bar');\n```\nSpecial handling (with de-duplication) for reading arrays:\n\n```\n    \u003c?php\n    \n    $stuff = $this-\u003erequireArrayParameter('stuff');\n```\nHandles nested JSON and form properties just fine:\n\n```\n    \u003c?php\n    \n    // Corresponds with {\"foo\": {\"bar\": {\"id\": 9}}}\n    list($foo, $bar_id) = $this-\u003erequireParameters('foo', 'foo.bar.id');\n```\n\n### CORS Middleware\nConfiguring the CORS middleware is as simple as adding `Fuzz\\ApiServer\\Routing\\CorsMiddleware` to the `$middleware` array in `app/Http/Kernel.php`.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fml-opensource%2Frest-api-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fml-opensource%2Frest-api-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fml-opensource%2Frest-api-server/lists"}