actions.json
The actions.json file is a fundamental part of the Solana Actions specification, as it establishes a mapping between the API and its associated actions.
It is also important to highlight the presence of this file for clients that render Blinks using Solana Actions.
The actions.json
file enables you to configure the accessibility of your paths for external consumers through various rules, including Path Matching, Exact Match, and Wildcard Match. By default, the actions.json
file for a znap project is structured as follows:
{
"rules": [
{
"pathPattern": "/**",
"apiPath": "/api/**"
}
]
}
In the example above, this rule establishes a general mapping that redirects all routes arriving at the site to their corresponding paths in the API, while maintaining the original route structure with the prefix /api/
. This approach is useful for handling requests uniformly and for redirecting to various API endpoints without the need to define each one individually.
Example
Imagine you have a website https://nftstore.com
, which is an online marketplace for buying and selling NFT collections. When you visit a specific NFT, such as https://nftstore.com/collections/madlads/2691
, you can customize its behavior by the file actions.json
.
In this file, you can define a rule that says: "Any URL starting with '/collections/
' and having two additional segments (like '/madlads/2691
') should be sent to my Solana Action API." Once this happens, we can execute actions related to the NFT, such as creating instructions for buying or selling.
These can be either internal API URLs within your website or external API URLs.
{
"rules": [
{
"pathPattern": "/collections/*/*",
"apiPath": "https://api.nftstore.com/actions/collections/*/*"
}
]
}
If a user accesses a URL like https://nftstore.com/collections/madlads/2691
, the request will be automatically routed to your Solana Actions API https://api.nftstore.com/actions/collections/madlads/2691
to process the action associated with that NFT. However, if the URL doesn't start with '/collections/
', the request won't be sent to the API.
Read the complete documentation for actions.json
at the following link