Skip to content

Unit Conversion

The /convert endpoint allows you to convert values between units of the same category. You need to provide a value to convert, a source unit, and the target unit.

Parameters

ParameterRequiredDescription
valueYesThe numeric value to convert
fromYesThe source unit (see available units below)
toYesThe target unit (must be in the same category as from)

Available Units

Temperature:

UnitDescription
celsiusCelsius degrees
fahrenheitFahrenheit degrees
kelvinKelvin

Length:

UnitDescription
kmKilometers
miMiles
mMeters
ftFeet
cmCentimeters
inInches
ydYards

Weight:

UnitDescription
kgKilograms
lbPounds
ozOunces
gGrams
tonMetric tons

Data:

UnitDescription
bBytes
kbKilobytes
mbMegabytes
gbGigabytes
tbTerabytes

Speed:

UnitDescription
km/hKilometers/hour
mphMiles/hour
m/sMeters/second
knotsKnots

Response Fields

FieldTypeDescription
fromstringSource unit
tostringTarget unit
valuenumberOriginal value to convert
resultnumberConverted value

Code Examples

curl -X GET \
  "https://api.sylvain.sh/v5/convert?value=100&from=km&to=mi"

Try It

Error Handling

If parameters are missing or invalid, the API will return an error:

Error MessageDescription
Please provide a valid value (?value={value})The value parameter is missing or invalid
Please provide a valid source unit (&from={unit})The from parameter is missing or invalid
Please provide a valid target unit (&to={unit})The to parameter is missing or invalid
Value must be a numberThe value is not a valid number
Invalid conversion unitThe from/to combination is not valid
Value must be greater than absolute zeroThe value is below absolute zero (temperature only)