Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Can Runway be used with GraphQL or REST APIs for fetching Eloquent models


Can Runway be used with GraphQL or REST APIs for fetching Eloquent models


Yes, Runway can be used with both GraphQL and REST APIs for fetching Eloquent models in Statamic.

GraphQL API Integration:
- Runway extends Statamic's built-in GraphQL API to allow querying your Eloquent models.
- You can enable GraphQL support for your Eloquent models in the `config/runway.php` file by setting the `'graphql' => true` option.
- This allows you to write GraphQL queries to fetch data from your Eloquent models, including support for filtering, sorting, and pagination.
- Runway automatically handles the mapping between your Eloquent models and the GraphQL schema, making it easy to integrate your data.

REST API Integration:
- Runway integrates with Statamic's built-in REST API to provide access to your Eloquent models.
- You can enable the REST API endpoints for your Eloquent models in the `config/statamic/api.php` file by adding them to the `'runway'` section.
- This will create two endpoints for each of your Eloquent models:
- `/api/runway/{resourceHandle}` to retrieve a list of models
- `/api/runway/{resourceHandle}/{id}` to retrieve a specific model
- Runway also supports filtering the REST API responses by defining the `'allowed_filters'` in the `config/statamic/api.php` file.

By leveraging Runway's integration with both GraphQL and REST APIs, you can seamlessly expose your Eloquent models to your front-end applications, external services, or any other system that needs to consume your Statamic-powered data.

This flexibility allows you to choose the API approach that best fits your project's requirements, whether that's a GraphQL-based architecture or a more traditional REST-based approach.

Citations:
[1] https://runway.duncanmcclean.com/rest-api
[2] https://statamic.com/addons/rad-pack/runway
[3] https://runway.duncanmcclean.com/graphql
[4] https://statamic.dev/rest-api
[5] https://statamic.dev/graphql