Ajar
Ajar is an O(1) fetch client for APIs that implement the OpenAPI specification. It consumes a generic interface generated by openapi-typescript-codegen
and returns a fully typed, deeply nested object that maps to fetch calls.
const client = Ajar<paths>()
client.feeds.get()
client.user["500"].comments.post()
client.user["500"].posts["3"].get()
Because it is implemented almost entirely using TypeScript's extensive type system, Ajar is largely capable of 'dissolving' during code compilation. In your app's bundle, all that remains is a lightweight1 core library that does not grow over time.
Currently, Ajar only implements a small subset of the OpenAPI specification2, however it should be more than enough for almost every project.
How it works
Ajar makes use of JavaScript proxies to create an infinitely nested object, and each entry exposes a number of methods. This roughly maps to:
type AjarObject = {
[key: string]: AjarObject
get: () => {}
post: () => {}
...
}
This object is then artificially restricted to a set of known paths using the type system. This approach is advantageous because it means there is no runtime growth.
Project status
Ajar is not currently usable. Almost all typing work has been completed, however the actual client is still a stub.
Credits
This project was heavily inspired by the hono client which pioneered our usage of proxies.
It all started with a message:
In the SolidJS discord, BTW ;)