API Overview
The Unit Conversion API provides accurate, fast, and reliable unit conversions for length, weight, temperature, volume, and area measurements. Perfect for applications, websites, and mobile apps that need conversion functionality.
Key Features
- Multiple Conversion Types: Length, Weight, Temperature, Volume, Area
- Batch Processing: Convert multiple values in a single request
- High Precision: Results accurate to 6 decimal places
- Rate Limiting: 1000 requests per hour per session
- RESTful Design: Clean, predictable API structure
- JSON Responses: Easy to parse and integrate
- CORS Enabled: Works from web browsers
- No Authentication: Simple to get started
Rate Limits
Free tier: 1000 requests per hour per session. Contact us for higher limits or commercial usage.
Response Format
All responses are in JSON format with consistent structure:
{
"status": "success|error",
"timestamp": "2025-06-22T10:30:00+00:00",
"data": { ... },
"api_version": "1.0"
}
API Endpoints
GET /api.php
Single Conversion via URL Parameters
GET /api.php?type={type}&from={from}&to={to}&value={value}
Parameters:
| Parameter |
Type |
Required |
Description |
| type |
string |
Yes |
Conversion type: length, weight, temperature, volume, area |
| from |
string |
Yes |
Source unit (e.g., "meters", "kg", "celsius") |
| to |
string |
Yes |
Target unit (e.g., "feet", "pounds", "fahrenheit") |
| value |
number |
Yes |
Numeric value to convert |
Example:
GET /api.php?type=length&from=meters&to=feet&value=10
POST /api.php
Single or Batch Conversions via JSON
Single Conversion:
{
"type": "length",
"from": "meters",
"to": "feet",
"value": 10
}
Batch Conversion:
{
"conversions": [
{"type": "length", "from": "meters", "to": "feet", "value": 10},
{"type": "weight", "from": "kg", "to": "pounds", "value": 5},
{"type": "temperature", "from": "celsius", "to": "fahrenheit", "value": 25}
]
}
GET /api.php?docs=1
API Documentation (JSON format)
Returns machine-readable API documentation including supported units and examples.
Usage Examples
JavaScript (Fetch API)
// GET request
fetch('https://unitconversioncalc.com/api.php?type=length&from=meters&to=feet&value=10')
.then(response => response.json())
.then(data => console.log(data));
// POST request - Single conversion
fetch('https://unitconversioncalc.com/api.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
type: 'weight',
from: 'kg',
to: 'pounds',
value: 70
})
})
.then(response => response.json())
.then(data => console.log(data));
// POST request - Batch conversion
fetch('https://unitconversioncalc.com/api.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
conversions: [
{type: 'length', from: 'meters', to: 'feet', value: 10},
{type: 'weight', from: 'kg', to: 'pounds', value: 5}
]
})
})
.then(response => response.json())
.then(data => console.log(data));
PHP (cURL)
'temperature',
'from' => 'celsius',
'to' => 'fahrenheit',
'value' => 25
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
?>
Python (Requests)
import requests
# GET request
response = requests.get('https://unitconversioncalc.com/api.php', params={
'type': 'volume',
'from': 'liters',
'to': 'gallons',
'value': 10
})
data = response.json()
# POST request
response = requests.post('https://unitconversioncalc.com/api.php', json={
'type': 'area',
'from': 'square_meters',
'to': 'square_feet',
'value': 100
})
data = response.json()
Response Examples
Successful Response:
{
"status": "success",
"timestamp": "2025-06-22T10:30:00+00:00",
"data": {
"success": true,
"type": "length",
"from": "meters",
"to": "feet",
"input_value": 10,
"result": 32.8084,
"formula": "m × 3.28084",
"precision": 6
},
"api_version": "1.0"
}
Error Response:
{
"status": "error",
"error": "Unsupported conversion type: distance. Supported: length, weight, temperature, volume, area",
"timestamp": "2025-06-22T10:30:00+00:00",
"api_version": "1.0"
}
API Tester
Test the API directly from this page:
Code Libraries & SDKs
JavaScript Library
class UnitConverter {
constructor(baseUrl = 'https://unitconversioncalc.com/api.php') {
this.baseUrl = baseUrl;
}
async convert(type, from, to, value) {
const response = await fetch(
`${this.baseUrl}?type=${type}&from=${from}&to=${to}&value=${value}`
);
return await response.json();
}
async batchConvert(conversions) {
const response = await fetch(this.baseUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ conversions })
});
return await response.json();
}
}
// Usage
const converter = new UnitConverter();
converter.convert('length', 'meters', 'feet', 10)
.then(result => console.log(result));
PHP Class
baseUrl = $baseUrl;
}
public function convert($type, $from, $to, $value) {
$url = $this->baseUrl . "?type=$type&from=$from&to=$to&value=$value";
$response = file_get_contents($url);
return json_decode($response, true);
}
public function batchConvert($conversions) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->baseUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['conversions' => $conversions]));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
}
// Usage
$converter = new UnitConverter();
$result = $converter->convert('weight', 'kg', 'pounds', 70);
?>
Python Class
import requests
class UnitConverter:
def __init__(self, base_url='https://unitconversioncalc.com/api.php'):
self.base_url = base_url
def convert(self, type_name, from_unit, to_unit, value):
response = requests.get(self.base_url, params={
'type': type_name,
'from': from_unit,
'to': to_unit,
'value': value
})
return response.json()
def batch_convert(self, conversions):
response = requests.post(self.base_url, json={
'conversions': conversions
})
return response.json()
# Usage
converter = UnitConverter()
result = converter.convert('temperature', 'celsius', 'fahrenheit', 25)
Need Help?
Contact us at api@unitconversioncalc.com for:
- Custom SDK development
- Higher rate limits
- Enterprise support
- Custom conversion types
- Integration assistance