Turn APIs into SDKs that developers love

Turning APIs into developer-friendly SDKs:

2930 SDKs*

and counting...

NPM Package Preview

Shopify GraphQL Storefront API

$ npx @samarium.sdk/new generate-gql "https://<your-store>.myshopify.com/api/2024-07/graphql.json" -h "X-Shopify-Storefront-Access-Token=<YOUR_ACCESS_TOKEN>" ./sdks/shopify.ts
NPM Package Preview

Salesforce GraphQL Developer API

$ npx @samarium.sdk/new generate-gql "https://<your-domain>.my.salesforce.com/services/data/v61.0/graphql" -h "Authorization=Bearer<YOUR_ACCESS_TOKEN>" ./sdks/salesforce.ts
NPM Package Preview

Contentful.com GraphQL API

$ npx @samarium.sdk/new generate-gql "https://graphql.contentful.com/content/v1/spaces/<your-space>/environments/<environment-name>" -h "Authorization=Bearer<YOUR_ACCESS_TOKEN>" ./sdks/contentful.ts
NPM Package Preview

Stigg.com GraphQL Server-API

$ npx @samarium.sdk/new generate-gql "https://api.stigg.io/graphql?apiKey=<server-api-key>" --endpoint "https://api.stigg.io/graphql" --auth-header-name X-API-KEY ./sdks/stigg.ts

Fully featured SDKs in seconds.

Ergonomic shortcuts for common API patterns, that feel natural.
No need to look up API docs or write boilerplate code.

Try it live! (100% locally in your browser)

Typesafety & True Custom Scalars

Forget about type casting, manual type checking or deserializing scalar values.
It's all there, out of the box.

Immediate Type Safety

(1)

Changes reflect immediately

(2)
import spacex from "spacex";
const company = await spacex.query.company(
({
ceo, // String
founded, // Int
}) => ({
ceo,
founded,
})
);
console.log(company);
const founded = company.founded;
const foundedIn2002 = founded === 2002;
// ✅ Type OK
// ✅ (founded is a number)
// { ceo: 'Elon Musk', founded: 2002 }

Custom Scalars

Custom scalars have to be serialized for network transport and often remain a string in most GraphQL clients , leaving you with the burden of deserializing them manually.

Not anymore. Dates and JSONs are automatically (lazily) deserialized for you and you can define your own custom scalars with full typesafety.

Full support for Custom Scalars

(1)
import sdk from "sdk";
const timeslots = await sdk.query.availableSlots(({
start, // DateTime
end, // DateTime
isBooked, // Boolean
}) => ({
start,
end,
isBooked,
}));
console.log(
timeslots
.filter((s) => !slot.isBooked)
.filter((s) => {
return s.start >= new Date()
});
// ----------- 👆 no need to parse,
// it's already a Date object!
);

Custom Scalars with custom parse

(1)

Custom Scalars with custom types

(2)
import sdk from "sdk";
sdk.init({
scalars: {
DateTime: (v: string) => {
return new Date(+v * 1000)
},
// ---- 👆 typesafe function:
// (v: string) => Date
// for example,
// convert a Unix timestamp
// to a Date object
},
});
const timeslots = await sdk.query.availableSlots(({
start, // DateTime
}) => ({
start,
}));
console.log(
timeslots
.filter((s) => {
return s.start >= new Date()
});
// ---------- 👆 no need to parse, it's already a Date object!
);

Authentication

Authenticate one or all requests with ease.
No weird hacks or workarounds. Just a simple, clean API.

Without Auth

(1)

.auth("token")

(2)

.auth({ Authorization: "token" })

(3)

.auth( async () => "token" | { Authorization: "token" })

(4)

Globally with .init({ auth: ... })

(5)
import sdk from "sdk";
const me = await sdk.query.me(({ id, username, email }) => ({
id,
username,
email,
}));
// ❌ Error! 401 Unauthenticated
console.log(me);

Explore more features on GitHub!