Compile any API to Typescript and then use it as fully typed SDK.
It's done in 10s and you'll never bother with GraphQL or clumsy OpenAPI fetch wrappers again.
APIs expose interfaces, so developers don't have to worry about the implementation details.
That's great, but you still have to handle the details of the communication. Be it GraphQL or REST.
We are so used to our Typescript & Copilot autocomplete heaven,
that it would be absolute dreamland if we could just use all APIs in the same way, like local code.
Well, welcome to dreamland. Introducing: The universal API to Typescript compiler, Samarium.
npx @samarium.sdk/new # this will start the assistant ui
import sdk from "./spacex"; // the file you created in the previous step
const { first10Launches } = await sdk((op) =>
op.query((q) => ({
first10Launches: q.launches({ limit: 10 })(({ id }) => ({ id })),
})),
);
Documentation is available here.
Additonally, you can take a look at the examples in the examples folder.
If you are interested in the technical details, you can take a look at the tests.
They are commented and cover all the features.
Also, feel free to open an issue if you need more examples or have questions.
In the playground you can compile your own GraphQL API by providing the introspection endpoint. It will fetch the schema, generate the sdk and load an editor with typescript.
You can execute the code and see console.log outputs, as well as the network requests.
Note: Right now the playground does not support authentication or headers. The CLI will prompt you for the authentication if needed and allows for more customization.
Online Playground is available here.
If you like the project, please consider giving it a star on GitHub. This helps to get the word out and to get more contributors on board. You can also reach me on x.com/liontariai for any questions or feedback.
Feedback is highly appreciated. Please open an issue if you have questions or suggestions!