TypeHub is a new platform to quickly build and share client SDKs and data models.

Explore   Sign up

Code Generator

TypeHub provides a powerful code generator which generates type-safe and ready to use client SDKs. At the basis TypeHub provides an editor to design a TypeAPI specification. The following page shows how our code generator transforms such a specification.

Editor

This screenshot shows an example specification configured through our editor.

Code

The following TypeScript example uses the generated code from the specification above. This example is in TypeScript but the API is very similar in other languages.

const client = new Client(baseUrl, new HttpBearer("[access_token]"));

// the startIndex and count query parameters are mapped to method arguments
// through the "person" tag the "getAll" operation is grouped under a "person" method
const collection = client.person().getAll(0, 16);

// the response of every operation is always a complete type-safe object, in this case it is a Collection object
collection.entries.forEach((person) => {
    console.log(person.firstName + " " + person.lastName);
});

try {
    // the insert operation has a payload argument which is mapped to the HTTP body and it returns a Message object
    const message = client.person().insert({
        firstName: "hello",
        lastName: "world",
    });

    if (message.success) {
        console.log("Insert successful");
    }
} catch (error) {
    // in case the server returns a 400 or 500 status code the client throws a MessageException
    if (error instanceof MessageException) {
        console.log("An error occurred: " . error.getPayload().message);
    }
}

interface Person {
    firstName?: string
    lastName?: string
}

interface Collection {
    entries?: Array<Person>
}

interface Message {
    success?: boolean
    message?: string
}