Code

At the following page you can take a look at the generated code, the code is based on this TypeAPI specification. This is only a demo to give you a first insight, for live examples feel free to login at the backend and use the live generator.

Client.ts

/**
 * Client automatically generated by SDKgen please do not edit this file manually
 * {@link https://sdkgen.app}
 */

import {ClientAbstract, CredentialsInterface, TokenStoreInterface, HttpRequest} from "sdkgen-client"
import {Anonymous} from "sdkgen-client"
import {ClientException, UnknownStatusCodeException} from "sdkgen-client";

import {TestTag} from "./TestTag";

export class Client extends ClientAbstract {
    public test(): TestTag
    {
        return new TestTag(
            this.httpClient,
            this.parser
        );
    }




    public static buildAnonymous(baseUrl: string): Client
    {
        return new Client(baseUrl, new Anonymous());
    }
}

Error.ts

/**
 * Error automatically generated by SDKgen please do not edit this file manually
 * {@link https://sdkgen.app}
 */

export interface Error {
    success?: boolean
    message?: string
}

ErrorException.ts

/**
 * ErrorException automatically generated by SDKgen please do not edit this file manually
 * {@link https://sdkgen.app}
 */

import {KnownStatusCodeException} from "sdkgen-client"

import {Error} from "./Error";

export class ErrorException extends KnownStatusCodeException {

    public constructor(private payload: Error) {
        super('The server returned an error');
    }

    public getPayload(): Error {
        return this.payload;
    }

}

HelloWorld.ts

/**
 * HelloWorld automatically generated by SDKgen please do not edit this file manually
 * {@link https://sdkgen.app}
 */

export interface HelloWorld {
    message?: string
}

Response.ts

/**
 * Response automatically generated by SDKgen please do not edit this file manually
 * {@link https://sdkgen.app}
 */

export interface Response {
    success?: boolean
    message?: string
}

TestTag.ts

/**
 * TestTag automatically generated by SDKgen please do not edit this file manually
 * {@link https://sdkgen.app}
 */

import {TagAbstract, HttpRequest} from "sdkgen-client"
import {ClientException, UnknownStatusCodeException} from "sdkgen-client";

import {Error} from "./Error";
import {ErrorException} from "./ErrorException";
import {HelloWorld} from "./HelloWorld";
import {Response} from "./Response";
import {Todo} from "./Todo";
import {Todos} from "./Todos";

export class TestTag extends TagAbstract {
    /**
     * Returns a hello world message
     *
     * @returns {Promise<HelloWorld>}
     * @throws {ClientException}
     */
    public async getHello(): Promise<HelloWorld> {
        const url = this.parser.url('/hello/world', {
        });

        let request: HttpRequest = {
            url: url,
            method: 'GET',
            headers: {
            },
            params: this.parser.query({
            }, [
            ]),
        };

        const response = await this.httpClient.request(request);
        if (response.ok) {
            return await response.json() as HelloWorld;
        }

        const statusCode = response.status;
        throw new UnknownStatusCodeException('The server returned an unknown status code: ' + statusCode);
    }
    /**
     * Returns available todo entries
     *
     * @returns {Promise<Todos>}
     * @throws {ClientException}
     */
    public async getEntries(startIndex?: number, count?: number): Promise<Todos> {
        const url = this.parser.url('/todo', {
        });

        let request: HttpRequest = {
            url: url,
            method: 'GET',
            headers: {
            },
            params: this.parser.query({
                'startIndex': startIndex,
                'count': count,
            }, [
            ]),
        };

        const response = await this.httpClient.request(request);
        if (response.ok) {
            return await response.json() as Todos;
        }

        const statusCode = response.status;
        throw new UnknownStatusCodeException('The server returned an unknown status code: ' + statusCode);
    }
    /**
     * Inserts a new todo entry
     *
     * @returns {Promise<Response>}
     * @throws {ClientException}
     */
    public async insert(payload: Todo): Promise<Response> {
        const url = this.parser.url('/todo', {
        });

        let request: HttpRequest = {
            url: url,
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            params: this.parser.query({
            }, [
            ]),
            data: payload
        };

        const response = await this.httpClient.request(request);
        if (response.ok) {
            return await response.json() as Response;
        }

        const statusCode = response.status;
        throw new UnknownStatusCodeException('The server returned an unknown status code: ' + statusCode);
    }
    /**
     * Returns a hello world message
     *
     * @returns {Promise<HelloWorld>}
     * @throws {ErrorException}
     * @throws {ClientException}
     */
    public async throwException(): Promise<HelloWorld> {
        const url = this.parser.url('/exception', {
        });

        let request: HttpRequest = {
            url: url,
            method: 'GET',
            headers: {
            },
            params: this.parser.query({
            }, [
            ]),
        };

        const response = await this.httpClient.request(request);
        if (response.ok) {
            return await response.json() as HelloWorld;
        }

        const statusCode = response.status;
        if (statusCode === 500) {
            throw new ErrorException(await response.json() as Error);
        }

        throw new UnknownStatusCodeException('The server returned an unknown status code: ' + statusCode);
    }



}

Todo.ts

/**
 * Todo automatically generated by SDKgen please do not edit this file manually
 * {@link https://sdkgen.app}
 */

export interface Todo {
    title?: string
}

Todos.ts

/**
 * Todos automatically generated by SDKgen please do not edit this file manually
 * {@link https://sdkgen.app}
 */

import {Todo} from "./Todo";

export interface Todos {
    totalResults?: number
    startIndex?: number
    itemsPerPage?: number
    entry?: Array<Todo>
}

part of the Apioo-Project