- How do I install reva2/jsonapi in a Laravel application?
- Install the package with Composer using the reva2/jsonapi package name. Laravel package discovery should register the service provider automatically in most setups. Check the package documentation for any publishable configuration or migration steps, then define your JSON:API resources and routes.
- Which Laravel versions does reva2/jsonapi support?
- The supported Laravel and PHP versions are defined by the package's Composer constraints. Check the package's composer.json or documentation before installing it in an existing application. If you are on an older or newer Laravel release, verify compatibility first to avoid dependency conflicts.
- What does JSON:API compliance mean for my Laravel API?
- JSON:API defines a standard document structure for resources, relationships, errors, pagination links, and metadata. A compliant API uses the application/vnd.api+json media type and consistent response shapes so clients can rely on predictable conventions. reva2/jsonapi is intended to handle these standardized responses with less boilerplate in Laravel.
- How do I define a JSON:API resource and its attributes?
- You typically create resource classes that map your Eloquent models or other data sources to JSON:API resource objects. Attributes and relationships are declared on those resource classes, and the package serializes them into compliant responses. Refer to the package documentation for the exact base classes and method signatures to use.
- How are relationships and includes handled by reva2/jsonapi?
- You define relationships on your JSON:API resources, such as belongsTo or hasMany associations. Clients can then request related data with the include query parameter, and the package resolves those relationships into the included section of the response. This produces compound documents while keeping relationship definitions centralized.
- Can I filter and sort JSON:API responses with this package?
- Yes, the package is designed to handle filtering and sorting for JSON:API endpoints. You define which filters and sort fields are allowed so clients can use query parameters without exposing arbitrary database columns. The package then applies those options and returns the results in the standard JSON:API response format.
- How does pagination work in reva2/jsonapi?
- Pagination is handled as part of the JSON:API response layer, typically using page-based query parameters and standardized links or metadata. You configure the page size and let the package generate the pagination details for clients. Check the documentation for the exact query parameter names and pagination strategy supported.
- How do I return JSON:API errors from a Laravel controller?
- The package is intended to help return standardized JSON:API error documents with fields such as status, title, detail, and source. You can map validation failures or exceptions into that error format instead of returning ad hoc JSON. Review the package's error handling documentation for the supported exception and response classes.
- Is reva2/jsonapi suitable for production use and how should I test it?
- Treat it like any Composer dependency: check its release history, maintenance activity, and compatibility with your Laravel and PHP versions before using it in production. Write feature tests that assert the JSON:API document structure, relationships, includes, filtering, sorting, and pagination behavior. Also test error responses and authentication or authorization boundaries around your endpoints.
- What are some alternatives to reva2/jsonapi for building JSON:API APIs in Laravel?
- Alternatives include laravel-json-api, which is a dedicated JSON:API package for Laravel, and more general tools such as spatie/laravel-query-builder or Fractal combined with custom serializers. Evaluate each option by Laravel version support, documentation, relationship and include handling, filtering capabilities, and ongoing maintenance. Choose the package whose conventions best match your team's API design and testing workflow.