Overview
The JSON plugin allows you to:- Fetch data from external JSON APIs
- Generate routes based on API responses
- Handle nested route parameters
- Support custom headers and HTTP agents
- Transform API responses with custom handlers
Configuration
To use the JSON plugin, configure it in yourscully.config.ts file:
Configuration Options
Each route parameter requires a configuration object with the following properties:The URL endpoint to fetch JSON data from. Supports ES6 template strings for dynamic URLs based on previous parameters.
The property path to extract from the JSON response. If not specified, the entire response is used.
Custom HTTP headers to include in the request.
Custom HTTP agent configuration for the request.
A custom function to transform the API response before processing.
Usage Examples
Basic Example
Generate routes from a simple user API:/blog/1/blog/2/blog/3
Nested Parameters
Create routes with multiple dynamic segments:postId URL uses template string syntax to reference the userId from the previous parameter.
Custom Headers
Add authentication or custom headers:Results Handler
Transform API responses before route generation:How It Works
- Route Parsing: Scully identifies route parameters (segments starting with
:) - Data Fetching: For each parameter, the plugin fetches data from the configured URL
- Data Extraction: If a
propertyis specified, it extracts that property from each item - Route Generation: Routes are generated for all possible combinations of parameter values
- Template Rendering: Subsequent parameters can use previous parameter values in their URLs
When to Use
Use the JSON plugin when you need to:- Generate pages from external API data
- Create dynamic routes based on database content
- Build pages for products, users, posts, or any entity from a REST API
- Integrate with third-party services that provide JSON endpoints
The JSON plugin runs during the build process. Make sure your API endpoints are accessible during the Scully build.
Error Handling
If the plugin fails to fetch data or encounters an error:- An error message is logged with the route information
- The route is returned without generated variations
- The build continues with other routes
Related
Content Folder Plugin
Generate routes from local content files
Router Plugin
Default router plugin for static routes

