HTML Entities Encoder/Decoder is a tool for encoding and decoding HTML entities. It converts special characters to HTML entities and vice versa to prevent XSS attacks and display special characters properly.
Add JitPack repository to your root build.gradle:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}Add the dependency:
dependencies {
implementation 'com.github.apiverve:htmlentities-api:1.1.14'
}import com.apiverve.htmlentities.HTMLEntitiesEncoderDecoderAPIClient;
import com.apiverve.htmlentities.APIResponse;
import com.apiverve.htmlentities.APIException;
// Initialize the client
HTMLEntitiesEncoderDecoderAPIClient client = new HTMLEntitiesEncoderDecoderAPIClient("YOUR_API_KEY");
try {
// Prepare request parameters
Map<String, Object> parameters = new HashMap<>();
parameters.put("html", "<div class=\"test\">Hello & World</div>");
parameters.put("action", "encode");
// Execute the request
APIResponse response = client.execute(parameters);
if (response.isSuccess()) {
// Handle successful response
JSONObject data = response.getData();
System.out.println("Success: " + data.toString());
} else {
// Handle API error
System.err.println("API Error: " + response.getError());
}
} catch (APIException e) {
// Handle exception
e.printStackTrace();
}// Some APIs don't require parameters
APIResponse response = client.execute();The SDK provides detailed error handling:
try {
APIResponse response = client.execute(parameters);
if (response.isSuccess()) {
// Process success
} else {
// Handle API-level errors
System.err.println("Error: " + response.getError());
}
} catch (APIException e) {
if (e.isAuthenticationError()) {
System.err.println("Invalid API key");
} else if (e.isRateLimitError()) {
System.err.println("Rate limit exceeded");
} else if (e.isServerError()) {
System.err.println("Server error");
} else {
System.err.println("Error: " + e.getMessage());
}
}The APIResponse object provides several methods:
APIResponse response = client.execute(params);
// Check status
boolean success = response.isSuccess();
boolean error = response.isError();
// Get data
String status = response.getStatus();
String errorMsg = response.getError();
JSONObject data = response.getData();
int code = response.getCode();
// Get raw response
JSONObject raw = response.getRawResponse();For detailed API documentation, visit: https://docs.apiverve.com/ref/htmlentities
Get your API key from https://apiverve.com
- Java 8 or higher
- Android API level 21 (Lollipop) or higher
- Documentation: https://docs.apiverve.com/ref/htmlentities
- Issues: GitHub Issues
- Email: hello@apiverve.com
This SDK is released under the MIT License. See LICENSE for details.
APIVerve provides production-ready REST APIs for developers. Fast, reliable, and easy to integrate.