Skip to main content

Endpoint

POST /api/convert
Converts a numeric value from one unit to another within a specific category. The conversion is performed by the ICE server, with the Flask API acting as a proxy.

Request

Headers

Content-Type
string
required
Must be set to application/json

Body Parameters

categoria
string
required
The category of units to convert. Must be one of:
  • temperatura - Temperature conversions
  • longitud - Length/distance conversions
  • peso - Weight/mass conversions
  • velocidad - Speed/velocity conversions
Note: Case-insensitive (converted to lowercase internally)
valor
number
required
The numeric value to convert. Can be an integer or floating-point number.Example: 100, 32.5, -40
desde
string
required
The source unit to convert from. Available units depend on the category:temperatura: celsius, fahrenheit, kelvinlongitud: m, km, mi, ftpeso: kg, lb, gvelocidad: kmh, mph, msNote: Case-insensitive (converted to lowercase internally)
hasta
string
required
The target unit to convert to. Must be a valid unit for the specified category (see desde for available units).Note: Case-insensitive (converted to lowercase internally)

Request Example

{
  "categoria": "temperatura",
  "valor": 100,
  "desde": "celsius",
  "hasta": "fahrenheit"
}

Response

Success Response (200 OK)

resultado
number
The converted value as a floating-point number.

Example

{
  "resultado": 212.0
}

Error Responses

Returned when an unsupported category is provided.
{
  "error": "Categoría no reconocida: volumen"
}
Returned when an invalid unit is specified for the category. The error is thrown by the ICE server.
{
  "error": "Unidad inválida: yards is not supported"
}
Returned when the valor parameter cannot be converted to a number.
{
  "error": "Valor inválido: could not convert string to float: 'abc'"
}
Returned when the Flask server is not connected to the ICE server.
{
  "error": "Servidor ICE desconectado"
}
Solution: Ensure the ICE server is running with python3 server.py
Returned when an unexpected error occurs during conversion.
{
  "error": "Error en servidor: [error details]"
}

Conversion Examples

// Request
{
  "categoria": "temperatura",
  "valor": 0,
  "desde": "celsius",
  "hasta": "fahrenheit"
}

// Response
{
  "resultado": 32.0
}

Implementation Details

The conversion logic is implemented in the ICE server backend (web_server.py:118-125). The Flask API routes the request through the client wrapper to the appropriate ICE method:
  • temperaturacliente.convert_temperatura() → ICE convertirTemperatura()
  • longitudcliente.convert_longitud() → ICE convertirLongitud()
  • pesocliente.convert_peso() → ICE convertirPeso()
  • velocidadcliente.convert_velocidad() → ICE convertirVelocidad()

Edge Cases

Same Unit Conversion

While the frontend typically prevents same-unit conversions (e.g., celsius to celsius), the API will process these requests. The result will be the same as the input value.

Negative Values

The API supports negative values, which is important for temperature conversions:
{
  "categoria": "temperatura",
  "valor": -40,
  "desde": "celsius",
  "hasta": "fahrenheit"
}
// Result: -40.0 (the point where both scales are equal)

Floating-Point Precision

The API returns raw floating-point results. The frontend typically formats these to 6 decimal places (app.js:129):
const formatted = parseFloat(res.toFixed(6)).toString();
Be aware of floating-point precision limitations when working with very large or very small numbers.

Get Available Units

Retrieve valid units for a category

Check Connection Status

Verify ICE server connectivity

Build docs developers (and LLMs) love