HTML Minify API Documentation¶
Overview¶
The HTML Minify API provides a simple and safe way to minify HTML content by removing unnecessary whitespace and line breaks between tags.
It supports three input modes:
- Body Mode (direct HTML string)
- URL Mode (remote HTML file)
- File Mode (previously uploaded file reference)
The API returns a downloadable minified HTML file and a short preview of the result.
Endpoint (POST)¶
POST https://api.apidatatools.com/html-minify-api
Headers¶
| Header | Type | Required | Description |
|---|---|---|---|
x-api-key | string | Yes | Your API key for authentication |
Content-Type | string | Yes | Must be application/json for body mode |
x-source-type | string | Optional | Defines input mode: body (default), url, or file |
Accepted File Extensions¶
| Mode | Allowed Extensions |
|---|---|
| URL / File | .txt, .html |
Input Example (Body Mode)¶
<html>\n <body>\n <h1> Hello World </h1>\n </body>\n</html>
Input Example (URL Mode)¶
{
"url": "https://example.com/sample.html"
}
Input Example (File Mode)¶
{
"file": "user_uploads/upl_1234567890abcdef/sample.html"
}
Example Request¶
Synchronous (Body Input)¶
curl -X POST "https://api.apidatatools.com/html-minify-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "x-source-type: body" \
-d '<html>\n <body>\n <h1> Hello World </h1>\n </body>\n</html>'
Asynchronous (Remote File URL)¶
curl -X POST "https://api.apidatatools.com/html-minify-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "x-source-type: url" \
-d '{"url": "https://example.com/sample.html"}'
Asynchronous (Input File)¶
curl -X POST "https://api.apidatatools.com/html-minify-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "x-source-type: file" \
-d '{"file": "user_uploads/upl_1234567890abcdef/sample.html"}'
Example Response¶
Successful (Body Mode)¶
{
"status": "success",
"request_id": "c1a2b3d4-e5f6-7890-abcd-ef1234567890",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abcdef1234567890.html",
"preview": "<html><body><h1> Hello World </h1></body></html>"
}
Async Job Accepted¶
{
"status": "accepted",
"job_id": "job_1234567890abcdef",
"status_url": "https://api.apidatatools.com/jobs/job_1234567890abcdef",
"request_id": "c1a2b3d4-e5f6-7890-abcd-ef1234567890"
}
Error Handling¶
| Error Code | HTTP Status | Description | Example |
|---|---|---|---|
INVALID_HTML | 400 | Input HTML is missing or not a valid string | {"status":"error","error":"INVALID_HTML","details":{"message":"HTML input must be a non-empty string"}} |
HTML_MINIFY_ERROR | 400 | Failed to minify HTML due to unexpected parsing issue | {"status":"error","error":"HTML_MINIFY_ERROR","details":{"message":"Failed to Minify HTML."}} |
INVALID_URL | 400 | URL is missing or invalid | {"status":"error","error":"INVALID_URL","details":{"message":"Missing or invalid 'url'."}} |
URL_UNREACHABLE | 400 | Remote URL could not be reached | {"status":"error","error":"URL_UNREACHABLE","details":{"message":"Could not reach URL"}} |
URL_NOT_OK | 400 | Remote URL returned non-200 HTTP status | {"status":"error","error":"URL_NOT_OK","details":{"message":"URL returned HTTP 404, expected 200."}} |
FILE_TOO_LARGE | 413 | File exceeds plan limit | {"status":"error","error":"FILE_TOO_LARGE","details":{"message":"Remote file exceeds plan limit."}} |
INVALID_FILE_EXTENSION | 400 | File extension not allowed | {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Invalid or unsupported file extension"}} |
FILE_UNAVAILABLE | 400 | File not found in storage | {"status":"error","error":"FILE_UNAVAILABLE","details":{"message":"Could not access file"}} |
EMPTY_BODY | 400 | Request body is empty | {"status":"error","error":"EMPTY_BODY","details":{"message":"Request body is empty."}} |
PAYLOAD_TOO_LARGE | 413 | Request body exceeds plan size limit | {"status":"error","error":"PAYLOAD_TOO_LARGE","details":{"message":"Request body exceeds limit"}} |
INTERNAL_ERROR | 500 | Unexpected internal error | {"status":"error","error":"INTERNAL_ERROR","details":{"message":"Failed to process your request"}} |
Async Job Status¶
To check the status of an asynchronous job (URL or File mode), use the Status API.
Endpoint¶
GET https://api.apidatatools.com/jobs/{job_id}
Example Status Response for Async¶
Queued / Processing¶
{
"job_id": "job_1234567890abcdef",
"status": "queued",
"message": "Your job is being processed.",
"retry_after": 2
}
Successful¶
{
"job_id": "job_1234567890abcdef",
"status": "success",
"created_at": 1712345678,
"updated_at": 1712345689,
"result": {
"status": "success",
"request_id": "c1a2b3d4-e5f6-7890-abcd-ef1234567890",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abcdef1234567890.html",
"preview": "<html><body><h1> Hello World </h1></body></html>"
}
}
Failed¶
{
"job_id": "job_1234567890abcdef",
"status": "failed",
"error": {
"code": "HTML_MINIFY_ERROR",
"message": "Failed to Minify HTML.",
"details": {
"message": "Unexpected parsing error"
}
}
}
Notes for Developers¶
- The API supports synchronous (body) and asynchronous (url/file) modes.
- For asynchronous jobs, a
job_idandstatus_urlare returned immediately. - Use the Status API to poll job progress until completion.
- The output file is stored temporarily and accessible via the returned download URL.
- Each response includes a unique
request_idfor tracking and debugging. - Ensure that remote URLs or uploaded files have valid extensions (
.htmlor.txt). - The preview field in successful responses is limited to the first 100 KB of the minified HTML.