This a simple metric convertor.
This API exposes a multiple endpoints for converions.
https://toolnized.com/metric-converter/v1
To test or use this API, you will need a tool capable of sending HTTP requests, such as:
POST /convert/<metric-type>The main endpoint for metric conversion. The metric is passed directly in the URL path.
Method: POST
Path: /convert/<metric-type>
| Parameter | Type | Required | Description | Allowed |
|---|---|---|---|---|
metric-type
|
string |
Yes | This the type of metric the conversion is to be done on. | length,weight,temperature,area,volume,speed |
For conversion endpoints the API expects a JSON object with the following required fields:
| Field | Type | Required | Description |
|---|---|---|---|
value
|
number |
Yes | The numerical value to be converted. Must be a valid number. |
initial
|
string |
Yes | The unit of the starting value (e.g., "C", "Km","KG"). Must be one of the supported unit codes. |
expected
|
string |
Yes | The desired unit for the converted result (e.g., "F", "m", "lb"). Must be compatible with the initial category. |
To convert 100 Kilograms to Pounds (lb):
{
"value": 100,
"initial": "kg",
"expected": "lb"
}
This example demonstrates converting 100 Kilograms (kg) to Pounds (lb) by targeting the weight metric type.
curl -X POST "https://toolnized.com/metric-converter/v1/convert/weight" -H "Content-Type: application/json" -d
"{\"value\": 100, \"initial\": \"kg\", \"expected\": \"lb\"}"
A successful conversion returns the original input, the converted result, and the calculated value.
{
"answer":220.46244202,
"message":"success",
"type":"lb"
}
Returned if a required field like value is missing from the JSON payload:
{
"message": "Error message defined here"
}
Returned if the units cannot be converted to each other:
{
"message":"Failed - Unprocessable Entity:The conversions cannot occur for those metric initials"
}
This section details the common HTTP status codes you can expect when interacting with the API.
| Code | Status | Description |
|---|---|---|
| 200 | OK | The request was successful, and the conversion result is in the response body. |
| 400 | Bad Request | The request was malformed (e.g., missing value, initial, or expected fields in the JSON body, or value is not a valid number). |
| 404 | Not Found |
The URL path is incorrect, or the
<metric-type> in the path is not a supported
category (e.g., /convert/time).
|
| 422 | Unprocessable Entity |
The units are incompatible (e.g., trying to convert a
KG unit to a Km unit).
|
| 500 | Internal Server Error | A general server error occurred on the server side. |