METRIC CONVERTOR

This a simple metric convertor.


1. Overview

This API exposes a multiple endpoints for converions.


2. Prerequisites

To test or use this API, you will need a tool capable of sending HTTP requests, such as:


3. Endpoints

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>

Path Parameters

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

Body Data (JSON Payload)

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.
Example Request Body

To convert 100 Kilograms to Pounds (lb):

{
  "value": 100,
  "initial": "kg",
  "expected": "lb"
}

Example Full Request

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\"}"

Example Successful Response (200 OK)

A successful conversion returns the original input, the converted result, and the calculated value.

{
        "answer":220.46244202,
        "message":"success",
        "type":"lb"
    }

Example Error Response (400 Bad Request)

Returned if a required field like value is missing from the JSON payload:

{

  "message": "Error message defined here"
}

Example Error Response (422 Unprocessable Entity)

Returned if the units cannot be converted to each other:

{
        "message":"Failed - Unprocessable Entity:The conversions cannot occur for those metric initials"
    }

4. Status Codes and Error Handling

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.