SDKgen is a powerful code generator to automatically build client SDKs for your REST API.

Sign in   Sign up

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.cs

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


using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
using RestSharp;
using Sdkgen.Client;
using Sdkgen.Client.Credentials;
using Sdkgen.Client.Exception;


public class Client : ClientAbstract
{
    public Client(string baseUrl, ICredentials credentials) : base(baseUrl, credentials)
    {
    }

    public TestTag Test()
    {
        return new TestTag(
            this.HttpClient,
            this.Parser
        );
    }



    public static Client Build(ICredentials credentials)
    {
        return new Client("https://api.sdkgen.app/", credentials);
    }
}

Error.cs

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

using System.Text.Json.Serialization;
public class Error
{
    [JsonPropertyName("success")]
    public bool? Success { get; set; }
    [JsonPropertyName("message")]
    public string? Message { get; set; }
}

ErrorException.cs

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


using Sdkgen.Client.Exception;


public class ErrorException : KnownStatusCodeException
{
    public Error Payload;

    public ErrorException(Error payload)
    {
        this.Payload = payload;
    }
}

HelloWorld.cs

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

using System.Text.Json.Serialization;
public class HelloWorld
{
    [JsonPropertyName("message")]
    public string? Message { get; set; }
}

Response.cs

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

using System.Text.Json.Serialization;
public class Response
{
    [JsonPropertyName("success")]
    public bool? Success { get; set; }
    [JsonPropertyName("message")]
    public string? Message { get; set; }
}

TestTag.cs

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


using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
using RestSharp;
using Sdkgen.Client;
using Sdkgen.Client.Exception;


public class TestTag : TagAbstract {
    public TestTag(RestClient httpClient, Parser parser): base(httpClient, parser)
    {
    }


    /**
     * Returns a hello world message
     */
    public async Task<HelloWorld> GetHello()
    {
        try
        {
            Dictionary<string, object> pathParams = new Dictionary<string, object>();

            Dictionary<string, object> queryParams = new Dictionary<string, object>();

            List<string> queryStructNames = new List<string>();

            RestRequest request = new RestRequest(this.Parser.Url("/hello/world", pathParams), Method.Get);
            this.Parser.Query(request, queryParams, queryStructNames);

            RestResponse response = await this.HttpClient.ExecuteAsync(request);

            if (response.IsSuccessful)
            {
                return this.Parser.Parse<HelloWorld>(response.Content);
            }

            switch ((int) response.StatusCode)
            {
                default:
                    throw new UnknownStatusCodeException("The server returned an unknown status code");
            }
        }
        catch (ClientException e)
        {
            throw e;
        }
        catch (System.Exception e)
        {
            throw new ClientException("An unknown error occurred: " + e.Message, e);
        }
    }

    /**
     * Returns available todo entries
     */
    public async Task<Todos> GetEntries(int startIndex, int count)
    {
        try
        {
            Dictionary<string, object> pathParams = new Dictionary<string, object>();

            Dictionary<string, object> queryParams = new Dictionary<string, object>();
            queryParams.Add("startIndex", startIndex);
            queryParams.Add("count", count);

            List<string> queryStructNames = new List<string>();

            RestRequest request = new RestRequest(this.Parser.Url("/todo", pathParams), Method.Get);
            this.Parser.Query(request, queryParams, queryStructNames);

            RestResponse response = await this.HttpClient.ExecuteAsync(request);

            if (response.IsSuccessful)
            {
                return this.Parser.Parse<Todos>(response.Content);
            }

            switch ((int) response.StatusCode)
            {
                default:
                    throw new UnknownStatusCodeException("The server returned an unknown status code");
            }
        }
        catch (ClientException e)
        {
            throw e;
        }
        catch (System.Exception e)
        {
            throw new ClientException("An unknown error occurred: " + e.Message, e);
        }
    }

    /**
     * Inserts a new todo entry
     */
    public async Task<Response> Insert(Todo payload)
    {
        try
        {
            Dictionary<string, object> pathParams = new Dictionary<string, object>();

            Dictionary<string, object> queryParams = new Dictionary<string, object>();

            List<string> queryStructNames = new List<string>();

            RestRequest request = new RestRequest(this.Parser.Url("/todo", pathParams), Method.Post);
            this.Parser.Query(request, queryParams, queryStructNames);
            request.AddJsonBody(JsonSerializer.Serialize(payload));

            RestResponse response = await this.HttpClient.ExecuteAsync(request);

            if (response.IsSuccessful)
            {
                return this.Parser.Parse<Response>(response.Content);
            }

            switch ((int) response.StatusCode)
            {
                default:
                    throw new UnknownStatusCodeException("The server returned an unknown status code");
            }
        }
        catch (ClientException e)
        {
            throw e;
        }
        catch (System.Exception e)
        {
            throw new ClientException("An unknown error occurred: " + e.Message, e);
        }
    }

    /**
     * Returns a hello world message
     */
    public async Task<HelloWorld> ThrowException()
    {
        try
        {
            Dictionary<string, object> pathParams = new Dictionary<string, object>();

            Dictionary<string, object> queryParams = new Dictionary<string, object>();

            List<string> queryStructNames = new List<string>();

            RestRequest request = new RestRequest(this.Parser.Url("/exception", pathParams), Method.Get);
            this.Parser.Query(request, queryParams, queryStructNames);

            RestResponse response = await this.HttpClient.ExecuteAsync(request);

            if (response.IsSuccessful)
            {
                return this.Parser.Parse<HelloWorld>(response.Content);
            }

            switch ((int) response.StatusCode)
            {
                case 500:
                    throw new ErrorException(this.Parser.Parse<Error>(response.Content));
                default:
                    throw new UnknownStatusCodeException("The server returned an unknown status code");
            }
        }
        catch (ClientException e)
        {
            throw e;
        }
        catch (System.Exception e)
        {
            throw new ClientException("An unknown error occurred: " + e.Message, e);
        }
    }


}

Todo.cs

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

using System.Text.Json.Serialization;
public class Todo
{
    [JsonPropertyName("title")]
    public string? Title { get; set; }
}

Todos.cs

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

using System.Text.Json.Serialization;
public class Todos
{
    [JsonPropertyName("totalResults")]
    public int? TotalResults { get; set; }
    [JsonPropertyName("startIndex")]
    public int? StartIndex { get; set; }
    [JsonPropertyName("itemsPerPage")]
    public int? ItemsPerPage { get; set; }
    [JsonPropertyName("entry")]
    public List<Todo>? Entry { get; set; }
}