actions.json
The actions.json file serves as a guide for Action Clients, indicating which website URLs support Ethereum Actions and providing a mapping for making GET requests to an Action API. This file helps translate regular website URLs into Action URLs that can be used to interact with Ethereum Actions.
The actions.json file should be stored and accessible at the root of the domain.
For example, if your web application is at my-site.com, the actions.json file should be accessible at https://my-site.com/actions.json. This file must be Cross-Origin accessible from any browser by including an Access-Control-Allow-Origin header with a value of *.
Rules
The rules field allows mapping a set of website's relative route paths to corresponding Action API paths.
Type: Array of ActionRuleObject.
interface ActionRuleObject {
/** relative (preferred) or absolute path for rule mapping */
pathPattern: string;
/** relative (preferred) or absolute path supporting Action requests */
apiPath: string;
}pathPattern: A pattern matching incoming pathnames.apiPath: The destination path for Action requests, defined as an absolute pathname or external URL.
pathPattern
This pattern matches incoming pathnames and can be an absolute or relative path. It supports the following formats:
-
Exact Match: Matches the exact URL path.
- Example:
/exact-path - Example:
https://website.com/exact-path
- Example:
-
Wildcard Match: Uses wildcards to match character sequences in the URL path.
- Single segment (
*):/trade/*matches/trade/123and/trade/abc - Multiple segments (
**):/category/*/item/**matches/category/123/item/456and/category/abc/item/def - Mixed:
/api/actions/trade/*/confirmmatches/api/actions/trade/123/confirm
- Single segment (
apiPath
The destination path for Action requests, defined as an absolute pathname or external URL.
Examples:
/api/exact-pathhttps://api.example.com/v1/donate/*/api/category/*/item/*/api/swap/**
Query parameters
Query parameters from the original URL are always preserved and appended to the mapped URL.
Path Matching
Path matching patterns use the following syntax:
| Operator | Matches |
|---|---|
* | A single path segment, excluding surrounding path separator (/) characters. |
** | Zero or more characters, including path separators (/) between multiple segments. If used with other operators, ** must be the last operator. |
? | Not supported. |
Rules Examples
- Exact match rule:
Maps requests to
/buyfrom your site's root to/api/buyrelative to your site's root:
{
"rules": [
{
"pathPattern": "/buy",
"apiPath": "/api/buy"
}
]
}- Wildcard path matching:
Maps requests to any path (excluding subdirectories) under
/actions/from your site's root to a corresponding path under/api/actions/:
{
"rules": [
{
"pathPattern": "/actions/*",
"apiPath": "/api/actions/*"
}
]
}- Wildcard path matching with external API:
Maps requests to any path (excluding subdirectories) under
/donate/from your site's root to a corresponding absolute path on an external site:
{
"rules": [
{
"pathPattern": "/donate/*",
"apiPath": "https://api.example.com/api/v1/donate/*"
}
]
}- Idempotent rule with wildcard path matching:
Maps requests to any path (including subdirectories) under
/api/actions/from your site's root to itself:
{
"rules": [
{
"pathPattern": "/api/actions/**",
"apiPath": "/api/actions/**"
}
]
}