At Hiro, we build and maintain a handful of API services, including:
- The Stacks Blockchain API for queries related to the Stacks blockchain
- The Token Metadata API for queries related to tokens on Stacks
- The Ordinals API for queries related to Bitcoin ordinals
Over the past few years, Hiro’s API team built a number of tools to simplify API development to make their lives easier, such as tools to help with database management, application shutdown handlers, migration helpers, and more.
We built these tools for us, but figured you may find them helpful too.
Today, we’re excited to tell you that this API toolkit is now open source, and you can use this toolkit for your own API development.
Meet Your New Favorite API Toolkit
The API Toolkit is an open source library that is a collection of tools for API builders. The goal of these various tools is to streamline development and improve code quality by offering convenient and reusable modules.
A comprehensive collection of tools to simplify common tasks in API development.
The toolkit includes a number of handy libraries, including:
- Postgres management: You don’t just want a Postgres library that works well. You want to manage Postgres transactions and make it easier to not mess up logic on how queries are bundled to make the code more readable. This management library handles those needs, including connection helpers with retry logic, migration tools, and more.
- Shutdown handlers: this library offers a way to properly shut down the API if it receives interrupt signals or exceptions it’s not designed to handle.
- Logger: this library offers a standardized way to issue JS logs in JSON using the pino JS library, so you can easily filter and query them in Grafana.
- Server versioning: Server versioning can be a surprisingly painful task. This library automates that workflow and generates versioning based on Git branch, tag, and latest commit.
- Fastify: This tool configures a Fastify server with CORS support, logger configs, and an automatic OpenAPI generator.
- Helpers: The toolkit also includes a variety of helpers that can do things like value conversion functions (converting hex strings and hashes) as well as timer tools for API profiling.
All of these tools are published as an NPM package, and you can start using them today. View the GitHub readme to get started.
The value of the API toolkit won’t stop there. We are still running 3 APIs, and we are working on tools to make our lives easier, and we plan to open source those tools to make your API development easier too.
That future work includes things like:
- CPU profiling: A suite of tools to profile API performance, useful for debugging
- Prometheus tools: Tools for taking stats and measurements of an API to gauge its performance
- Testing utilities: Various other testing functionalities
Keep an eye on the repo for new improvements to the library.
At Hiro, we believe in building open source tech. We want to enable you to ship quickly, with confidence, and that fundamental belief is instilled with every product we create and every library we release.
We hope you find this API toolkit as helpful as we do. Happy coding.