Java 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.java

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


import app.sdkgen.client.ClientAbstract;
import app.sdkgen.client.Credentials.*;
import app.sdkgen.client.CredentialsInterface;
import app.sdkgen.client.Exception.Authenticator.InvalidCredentialsException;
import app.sdkgen.client.Exception.ClientException;
import app.sdkgen.client.Exception.UnknownStatusCodeException;
import app.sdkgen.client.Parser;
import app.sdkgen.client.TokenStoreInterface;
import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.hc.client5.http.classic.methods.*;
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.*;
import org.apache.hc.core5.net.URIBuilder;
import org.apache.hc.core5.net.URLEncodedUtils;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Client extends ClientAbstract {
    public Client(String baseUrl, CredentialsInterface credentials) throws InvalidCredentialsException {
        super(baseUrl, credentials);
    }

    public TestTag test()
    {
        return new TestTag(
            this.httpClient,
            this.objectMapper,
            this.parser
        );
    }




    public static Client buildAnonymous(String baseUrl) throws InvalidCredentialsException
    {
        return new Client(baseUrl, new Anonymous());
    }
}

Error.java

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


import com.fasterxml.jackson.annotation.*;

public class Error {
    private Boolean success;
    private String message;

    @JsonSetter("success")
    public void setSuccess(Boolean success) {
        this.success = success;
    }

    @JsonGetter("success")
    public Boolean getSuccess() {
        return this.success;
    }

    @JsonSetter("message")
    public void setMessage(String message) {
        this.message = message;
    }

    @JsonGetter("message")
    public String getMessage() {
        return this.message;
    }
}

ErrorException.java

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


import app.sdkgen.client.Exception.KnownStatusCodeException;

public class ErrorException extends KnownStatusCodeException {

    private Error payload;

    public ErrorException(Error payload) {
        super("The server returned an error");

        this.payload = payload;
    }

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

}

HelloWorld.java

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


import com.fasterxml.jackson.annotation.*;

public class HelloWorld {
    private String message;

    @JsonSetter("message")
    public void setMessage(String message) {
        this.message = message;
    }

    @JsonGetter("message")
    public String getMessage() {
        return this.message;
    }
}

Response.java

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


import com.fasterxml.jackson.annotation.*;

public class Response {
    private Boolean success;
    private String message;

    @JsonSetter("success")
    public void setSuccess(Boolean success) {
        this.success = success;
    }

    @JsonGetter("success")
    public Boolean getSuccess() {
        return this.success;
    }

    @JsonSetter("message")
    public void setMessage(String message) {
        this.message = message;
    }

    @JsonGetter("message")
    public String getMessage() {
        return this.message;
    }
}

TestTag.java

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


import app.sdkgen.client.Exception.ClientException;
import app.sdkgen.client.Exception.UnknownStatusCodeException;
import app.sdkgen.client.Parser;
import app.sdkgen.client.TagAbstract;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.classic.methods.*;
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.*;
import org.apache.hc.core5.net.URIBuilder;
import org.apache.hc.core5.net.URLEncodedUtils;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestTag extends TagAbstract {
    public TestTag(HttpClient httpClient, ObjectMapper objectMapper, Parser parser) {
        super(httpClient, objectMapper, parser);
    }


    /**
     * Returns a hello world message
     */
    public HelloWorld getHello() throws ClientException {
        try {
            Map<String, Object> pathParams = new HashMap<>();

            Map<String, Object> queryParams = new HashMap<>();

            List<String> queryStructNames = new ArrayList<>();

            URIBuilder builder = new URIBuilder(this.parser.url("/hello/world", pathParams));
            this.parser.query(builder, queryParams, queryStructNames);

            HttpGet request = new HttpGet(builder.build());


            return this.httpClient.execute(request, response -> {
                if (response.getCode() >= 200 && response.getCode() <= 299) {
                    var data = this.parser.parse(EntityUtils.toString(response.getEntity()), new TypeReference<HelloWorld>(){});

                    return data;
                }

                var statusCode = response.getCode();
                throw new UnknownStatusCodeException("The server returned an unknown status code: " + statusCode);
            });
        } catch (ClientException e) {
            throw e;
        } catch (URISyntaxException | IOException e) {
            throw new ClientException("An unknown error occurred: " + e.getMessage(), e);
        }
    }

    /**
     * Returns available todo entries
     */
    public Todos getEntries(Integer startIndex, Integer count) throws ClientException {
        try {
            Map<String, Object> pathParams = new HashMap<>();

            Map<String, Object> queryParams = new HashMap<>();
            queryParams.put("startIndex", startIndex);
            queryParams.put("count", count);

            List<String> queryStructNames = new ArrayList<>();

            URIBuilder builder = new URIBuilder(this.parser.url("/todo", pathParams));
            this.parser.query(builder, queryParams, queryStructNames);

            HttpGet request = new HttpGet(builder.build());


            return this.httpClient.execute(request, response -> {
                if (response.getCode() >= 200 && response.getCode() <= 299) {
                    var data = this.parser.parse(EntityUtils.toString(response.getEntity()), new TypeReference<Todos>(){});

                    return data;
                }

                var statusCode = response.getCode();
                throw new UnknownStatusCodeException("The server returned an unknown status code: " + statusCode);
            });
        } catch (ClientException e) {
            throw e;
        } catch (URISyntaxException | IOException e) {
            throw new ClientException("An unknown error occurred: " + e.getMessage(), e);
        }
    }

    /**
     * Inserts a new todo entry
     */
    public Response insert(Todo payload) throws ClientException {
        try {
            Map<String, Object> pathParams = new HashMap<>();

            Map<String, Object> queryParams = new HashMap<>();

            List<String> queryStructNames = new ArrayList<>();

            URIBuilder builder = new URIBuilder(this.parser.url("/todo", pathParams));
            this.parser.query(builder, queryParams, queryStructNames);

            HttpPost request = new HttpPost(builder.build());
            request.setEntity(new StringEntity(this.objectMapper.writeValueAsString(payload), ContentType.APPLICATION_JSON));

            request.setHeader("Content-Type", "application/json");

            return this.httpClient.execute(request, response -> {
                if (response.getCode() >= 200 && response.getCode() <= 299) {
                    var data = this.parser.parse(EntityUtils.toString(response.getEntity()), new TypeReference<Response>(){});

                    return data;
                }

                var statusCode = response.getCode();
                throw new UnknownStatusCodeException("The server returned an unknown status code: " + statusCode);
            });
        } catch (ClientException e) {
            throw e;
        } catch (URISyntaxException | IOException e) {
            throw new ClientException("An unknown error occurred: " + e.getMessage(), e);
        }
    }

    /**
     * Returns a hello world message
     */
    public HelloWorld throwException() throws ClientException {
        try {
            Map<String, Object> pathParams = new HashMap<>();

            Map<String, Object> queryParams = new HashMap<>();

            List<String> queryStructNames = new ArrayList<>();

            URIBuilder builder = new URIBuilder(this.parser.url("/exception", pathParams));
            this.parser.query(builder, queryParams, queryStructNames);

            HttpGet request = new HttpGet(builder.build());


            return this.httpClient.execute(request, response -> {
                if (response.getCode() >= 200 && response.getCode() <= 299) {
                    var data = this.parser.parse(EntityUtils.toString(response.getEntity()), new TypeReference<HelloWorld>(){});

                    return data;
                }

                var statusCode = response.getCode();
                if (statusCode == 500) {
                    var data = this.parser.parse(EntityUtils.toString(response.getEntity()), new TypeReference<Error>(){});

                    throw new ErrorException(data);
                }

                throw new UnknownStatusCodeException("The server returned an unknown status code: " + statusCode);
            });
        } catch (ClientException e) {
            throw e;
        } catch (URISyntaxException | IOException e) {
            throw new ClientException("An unknown error occurred: " + e.getMessage(), e);
        }
    }



}

Todo.java

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


import com.fasterxml.jackson.annotation.*;

public class Todo {
    private String title;

    @JsonSetter("title")
    public void setTitle(String title) {
        this.title = title;
    }

    @JsonGetter("title")
    public String getTitle() {
        return this.title;
    }
}

Todos.java

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


import com.fasterxml.jackson.annotation.*;

public class Todos {
    private Integer totalResults;
    private Integer startIndex;
    private Integer itemsPerPage;
    private java.util.List<Todo> entry;

    @JsonSetter("totalResults")
    public void setTotalResults(Integer totalResults) {
        this.totalResults = totalResults;
    }

    @JsonGetter("totalResults")
    public Integer getTotalResults() {
        return this.totalResults;
    }

    @JsonSetter("startIndex")
    public void setStartIndex(Integer startIndex) {
        this.startIndex = startIndex;
    }

    @JsonGetter("startIndex")
    public Integer getStartIndex() {
        return this.startIndex;
    }

    @JsonSetter("itemsPerPage")
    public void setItemsPerPage(Integer itemsPerPage) {
        this.itemsPerPage = itemsPerPage;
    }

    @JsonGetter("itemsPerPage")
    public Integer getItemsPerPage() {
        return this.itemsPerPage;
    }

    @JsonSetter("entry")
    public void setEntry(java.util.List<Todo> entry) {
        this.entry = entry;
    }

    @JsonGetter("entry")
    public java.util.List<Todo> getEntry() {
        return this.entry;
    }
}

part of the Apioo-Project