Typed API

API client-server library for TypeScript projects


flash_on

Speeds up development

You describe API like ordinar TypeScript class. Interface for Frontend will be generated.
Then you need only to configure connectors (WebSocket and HTTP available).

settings

Easy to work with

No need to learn complex configurations, just write code.
TypedAPI will validate all input data. You can be sure that string is string, object is object, Date is Date e t.c.

device_hub

Ready for microservices

In development you create api as monolith. Then from configuration you can split your API to services and say which method should be called in which pod.

Code sample

Example how to create API on backend
// Main api class
export class Api {
    books = new BooksApi
}

// Sample books api class that use some yours repository
export class BooksApi {

    get(id: number): Promise<BookResult> {
        return repository.get(id)
    }

    async create(createBookData: CreateBook): Promise<BookResult> {
        const bookResult = await repository.createBook(createBookData)
        this.onCreate.fire(bookResult)
    }

    async update(id: number, data: UpdateBook): Promise<void> {
        const bookResult = await repository.updateBook(id, data)
        this.onUpdate.fire(bookResult)
    }

    async remove(id: number): Promise<void> {
        await repository.deleteBook(id)
        this.onDelete.fire(id)
    }

    onCreate = new Event<BookResult>()
    onUpdate = new Event<BookResult>()
    onDelete = new Event<number>()
}

// Interfaces of data
export interface BookResult {
    id: number
    title: string
    description: string
}

export interface UpdateBook {
    title?: string
    description?: string
}

export interface CreateBook {
    title: string
    description: string
}
Auto-generated API interface

This interface will be generated automatically and will stored in Client application.
Data interfaces will be also added to generated file.

interface Api {
    books: {
        create(book: CreateBook): Promise<BookResult>
        get(id: number): Promise<BookResult>
        update(id: number, data: UpdateBook): Promise<void>
        remove(id: number): Promise<void>
        onCreate: Event<BookResult>
        onUpdate: Event<BookResult>
        onDelete: Event<number>
    }
}
Frontend code sample

Create book

let book = await api.books.create({title: "title", description: "description"})

Update book

await api.books.update(bookId, {title: "new title"})

Subscribe to Event

let subscription = await api.book.onUpdate.subscribe((book: BookResult) => {
    // do some stuff with updated book
})

Unsubscribe from event

await subscription.unsubscribe()