Skip to content

liontariai/samarium

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Samarium Hero Image
Samarium
The universal API to Typescript Compiler

Imagine having all APIs at your disposal, as if it was your local code.

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.

Quickstart

1. Compile the API to Typescript

npx @samarium.sdk/new # this will start the assistant ui

2. Import the API as Typescript SDK

import sdk from "./spacex"; // the file you created in the previous step

3. Use the SDK

const { first10Launches } = await sdk((op) =>
    op.query((q) => ({
        first10Launches: q.launches({ limit: 10 })(({ id }) => ({ id })),
    })),
);

Documentation & Examples

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.

Try it in the browser

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.

Samarium Online Playground

Support the project

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

Feedback is highly appreciated. Please open an issue if you have questions or suggestions!