Create Custom Callable APIs: Serverless Functions

Zephyr programs can also be turned into fully custom APIs to be externally called through web requests. That's thanks to serverless functions that can be defined in your program and called on request. These functions execute on-demand on our servers and can serve various purposes, such as:

  • Creating custom RPC-alike endpoints, useful for simulations and on-demand "getLedger" APIs.

  • Implementing querying APIs, which can be fully customized for composing stored and ledger data.

  • Designing customizable dashboards.

1. Custom RPC-alike endpoints

Contract Call Simulation

Having access to the ledger allows the Zephyr environment to accurately simulate contract calls. This can be used to create a simulation endpoint (in the form of serverless function) inside a program, eliminating the need for the user to rely on (and pay for) an external RPC provider to simulate its contract calls. Using Zephyr as a simulation endpoint also eliminates another hurdle by enabling direct data type conversions within the program using Rust and the Soroban type system.

On-demand getLedger APIs

You can also set a serverless function to act as a getLedger API endpoint, returning ledger data on-demand and composing it according to your logic.

2. Querying and composing stored data

As mentioned earlier, there are two methods for querying data stored in Mercury's database: the first is via the standardized GraphQL API, and the second involves using serverless functions. This latter option enables the creation of customizable API endpoints for querying data, including the ability to combine table and ledger queries within the same query/execution.

This approach is particularly advantageous and efficient because it minimizes the amount of data stored in the database. Furthermore, leveraging serverless functions allows you to parse table, event, and ledger data directly within the program using Rust and the Soroban type system. This means you can format the data for return to the caller, relieving the client from handling those complexities.

3. Create customizable dashboards

But that's not all. Zephyr functions can also be utilized to generate visually appealing charts and tables with minimal effort on the user's side. Simply provide Zephyr's data, plot it, and customize your own dashboards. Moreover, you can access publicly indexed data stored in other tables.

We're currently working on the community charts dashboard, where developers can create and publish charts related to their protocols, aggregations of various protocols, etc. Some public dashboards, curated by our team are already available in the curated charts section of the web app.

Last updated