{"id":17066842,"url":"https://github.com/tobyzerner/json-api-server","last_synced_at":"2025-04-04T08:07:09.560Z","repository":{"id":33776705,"uuid":"161715907","full_name":"tobyzerner/json-api-server","owner":"tobyzerner","description":"A JSON:API server implementation in PHP.","archived":false,"fork":false,"pushed_at":"2024-10-25T23:03:55.000Z","size":1207,"stargazers_count":64,"open_issues_count":19,"forks_count":20,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-10-30T03:43:02.578Z","etag":null,"topics":["eloquent","json-api","php"],"latest_commit_sha":null,"homepage":"https://tobyzerner.github.io/json-api-server/","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/tobyzerner.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-12-14T01:34:09.000Z","updated_at":"2024-10-17T11:22:18.000Z","dependencies_parsed_at":"2023-12-05T23:23:20.268Z","dependency_job_id":"1ac154ab-76a5-4bc9-bbc0-5cfb7a360e44","html_url":"https://github.com/tobyzerner/json-api-server","commit_stats":{"total_commits":249,"total_committers":9,"mean_commits":"27.666666666666668","dds":"0.10040160642570284","last_synced_commit":"0689c31cd1124ef45b9101ea121c8f8fafefa071"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobyzerner%2Fjson-api-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobyzerner%2Fjson-api-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobyzerner%2Fjson-api-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobyzerner%2Fjson-api-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tobyzerner","download_url":"https://codeload.github.com/tobyzerner/json-api-server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247142065,"owners_count":20890652,"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":["eloquent","json-api","php"],"created_at":"2024-10-14T11:08:32.024Z","updated_at":"2025-04-04T08:07:09.544Z","avatar_url":"https://github.com/tobyzerner.png","language":"PHP","readme":"# json-api-server\n\n[![Pre Release](https://img.shields.io/packagist/vpre/tobyz/json-api-server.svg?style=flat)](https://github.com/tobyzerner/json-api-server/releases)\n[![License](https://img.shields.io/packagist/l/tobyz/json-api-server.svg?style=flat)](https://packagist.org/packages/tobyz/json-api-server)\n\njson-api-server is a [JSON:API](http://jsonapi.org) server implementation in\nPHP.\n\nIt allows you to build a feature-rich API by defining resource schema and\nconnecting it to your application's database layer.\n\nBased on your schema definition, the package will serve a complete API that\nconforms to the [JSON:API specification](https://jsonapi.org/format/), including\nsupport for:\n\n-   **Showing** individual resources (`GET /articles/1`)\n-   **Listing** resource collections (`GET /articles`)\n-   **Sorting**, **filtering**, **pagination**, and **sparse fieldsets**\n-   **Compound documents** with inclusion of related resources\n-   **Creating** resources (`POST /articles`)\n-   **Updating** resources (`PATCH /articles/1`)\n-   **Deleting** resources (`DELETE /articles/1`)\n-   **Content negotiation**\n-   **Error handling**\n-   **Extensions** including Atomic Operations\n-   **Generating OpenAPI definitions**\n\n## Documentation\n\n[Read the documentation](https://tobyzerner.github.io/json-api-server)\n\n## Example\n\nThe following example uses an Eloquent model in a Laravel application. However,\njson-api-server can be used with any framework that can deal in PSR-7 Requests\nand Responses. Custom behavior can be implemented to support other ORMs and data\npersistence layers.\n\n```php\nuse App\\Models\\User;\nuse Tobyz\\JsonApiServer\\Laravel;\nuse Tobyz\\JsonApiServer\\Laravel\\EloquentResource;\nuse Tobyz\\JsonApiServer\\Laravel\\Filter;\nuse Tobyz\\JsonApiServer\\Endpoint;\nuse Tobyz\\JsonApiServer\\Schema\\Field;\nuse Tobyz\\JsonApiServer\\Schema\\Type;\nuse Tobyz\\JsonApiServer\\JsonApi;\n\nclass UsersResource extends EloquentResource\n{\n    public function type(): string\n    {\n        return 'users';\n    }\n\n    public function newModel(Context $context): object\n    {\n        return new User();\n    }\n\n    public function endpoints(): array\n    {\n        return [\n            Endpoint\\Show::make(),\n            Endpoint\\Index::make()-\u003epaginate(),\n            Endpoint\\Create::make()-\u003evisible(Laravel\\can('create')),\n            Endpoint\\Update::make()-\u003evisible(Laravel\\can('update')),\n            Endpoint\\Delete::make()-\u003evisible(Laravel\\can('delete')),\n        ];\n    }\n\n    public function fields(): array\n    {\n        return [\n            Field\\Attribute::make('name')\n                -\u003etype(Type\\Str::make())\n                -\u003ewritable()\n                -\u003erequired(),\n\n            Field\\ToOne::make('address')-\u003eincludable(),\n\n            Field\\ToMany::make('friends')\n                -\u003etype('users')\n                -\u003eincludable(),\n        ];\n    }\n\n    public function filters(): array\n    {\n        return [Filter\\Where::make('id'), Filter\\Where::make('name')];\n    }\n}\n\n$api = new JsonApi();\n\n$api-\u003eresource(new UsersResource());\n\n/** @var Psr\\Http\\Message\\ServerRequestInterface $request */\n/** @var Psr\\Http\\Message\\ResponseInterface $response */\ntry {\n    $response = $api-\u003ehandle($request);\n} catch (Throwable $e) {\n    $response = $api-\u003eerror($e);\n}\n```\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to\ndiscuss what you would like to change.\n\n## License\n\n[MIT](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftobyzerner%2Fjson-api-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftobyzerner%2Fjson-api-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftobyzerner%2Fjson-api-server/lists"}