AP

APIs as First-Class Citizen

Hacker News

APIs as First-Class Citizen

A few years ago, I encountered neovim and a new concept: APIs as first-class citizens. As I used it more and more in my work, I became increasingly aware of its importance. Exposing the software's state and operations through APIs greatly improves the debugging experience, provides extensibility, and makes it very convenient for other programs to call them. On the other hand, centering on APIs can also improve program structure, because the entire program is written around a single context. Currently, I usually use HTTP as the external interface because it allows for operations using curl and exposes these operations to the front end. Previously, I used Axum as the HTTP server and utoipa to export the API to OpenAPI. Then, I used tools to convert the OpenAPI as TypeScript code for front-end. However, I quickly encountered some problems. First, utoipa's documentation isn't generated during the build process; I need to run `cargo test` separately to generate the OpenAPI documentation. Second, utoipa's procedural macros are sometimes complex than the functions themselves. Finally, Axum's type system is overly complex, making every interface writing or modification a painful experience. Furthermore, while OpenAPI to TypeScript tools are available, their quality is often inconsistent, and the generated code is rarely usable. I'm hoping for a tool that generates Rust/OpenAPI/TypeScript code by writing something like a proto file. For Rust, ideally, it would generate a trait, so implementing the trait would automatically implement the HTTP interface. In other words, I'd like a tool like this: ``` interface API { @get void hello_world(); @post string hello_world2(); }; ``` I've carefully studied tools like gRPC/TypeSpec, but I'm not entirely satisfied. Since I have prior experience writing parsers and code generation tools, I finally decided to create my own—[XIDL]( https://github.com/xidl/xidl ). I made the following improvements: First, I generated the trait and OpenAPI documentation using `xidl-build`, thus resolving the inconsistency in OpenAPI generation time. Second, I exposed the HTTP interface as an asynchronous trait, hiding its internal complexity within the generated codes. This eliminates the need for developers to struggle with Axum's complex types. Furthermore, I strictly defined the interface behavior using RFCs, ensuring consistent presentation across different languages. Simultaneously, I used [behave]( http://behave.readthedocs.io/en/stable/ ) and [hurl]( http://hurl.dev/ ) to ensure interoperability among all generators. Furthermore, I wrote a simple [LSP]( https://github.com/xidl/idl-language-server ) that allows real-time preview of the OpenAPI interface via scalars. This enables direct HTTP API calls within the browser.

Share card

Actual performance

3points
1comments
Did not reach leaderboard

Launch Intel predictions

Analyze your own launch →
Product HuntOn track for Day 1 leaderboard · Strong signals: mac, new, context · Missing: agents, macos, agent
95%95% predicted probability of success on Product Hunt, based on ML models trained on real launch data.
best fitHighest predicted score across all platforms for this description.
Indie HackersFits the IH revenue-focused audience · Strong signals: para · Missing: supports, reddit linkedin, podcasting
88%88% predicted probability of success on Indie Hackers, based on ML models trained on real launch data.
Hacker NewsStrong engagement from HN community · Strong signals: ide, io · Missing: https docs, excited, just released
69%69% predicted probability of success on Hacker News, based on ML models trained on real launch data.
nativeThis product was originally launched on this platform.
AppSumoMay struggle as an AppSumo deal · Strong signals: interface, calls · Missing: plus, platform, intuitive
41%41% predicted probability of success on AppSumo, based on ML models trained on real launch data.
TrustMRRLess likely to generate early MRR · Strong signals: para · Missing: mobile apps, ios, personal
40%40% predicted probability of success on TrustMRR, based on ML models trained on real launch data.
Acquire.comPre-revenue stage for this audience · Missing: arr, mrr, revenue
11%11% predicted probability of success on Acquire.com, based on ML models trained on real launch data.
BetaListMay not resonate with beta-testers · Missing: web3, chat, crypto
0%0% predicted probability of success on BetaList, based on ML models trained on real launch data.

Incorrect prediction on native model

Similar products

An
An opinionated TailwindCSS class sorter36%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

An opinionated TailwindCSS class sorter

Hacker News2
Fi
Fighting ICO Scammers with APIs51%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Fighting ICO Scammers with APIs

Hacker News9
Op
OpenAPI OAuth 2.0 scopes enforcement for APIs66%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

OpenAPI OAuth 2.0 scopes enforcement for APIs

Hacker News7
Ko
Kompy, a Wrapper for Komoot APIs30%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Kompy, a Wrapper for Komoot APIs

Hacker News1
Th
The Class Placements Game42%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

The Class Placements Game

Hacker News7
QuikQuit
QuikQuit63%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

QuikQuit: One-click resignation—class or sass.

Indie Hackers1$1/moai
De
Define JavaScript class methods outside of their class33%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Define JavaScript class methods outside of their class

Hacker News1
ClaimVault
ClaimVault48%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Find class action settlements you qualify for

Indie Hackers
Mercedes G Class For Rent in Dubai
Mercedes G Class For Rent in Dubai47%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Mercedes G-Class

Indie Hackers1$700/motravel
Ka
Kaptan, a Checker for Class Fields in Java24%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Kaptan, a Checker for Class Fields in Java

Hacker News2