Weight Converter API: The Complete Guide

Need to convert weight or mass units in your application? This guide covers everything you need to know about weight conversion via API, including metric and imperial units, conversion accuracy, and implementation examples in multiple languages.

Weight vs Mass

Technically, mass (measured in kilograms) and weight (measured in newtons) are different. However, in everyday usage and most applications, they're used interchangeably. The API handles common "weight" units that are technically measures of mass.

The metric system uses kilograms and grams, while the imperial system uses pounds and ounces. Converting between them is essential for international shipping, e-commerce, health apps, and cooking.

Supported Weight Units

Unit Code System
KilogramkgMetric
GramgMetric
MilligrammgMetric
Metric TontMetric
PoundlbImperial
OunceozImperial
StonestImperial (UK)
US TontonImperial
Common Conversions: 1 kg = 2.20462 lbs, 1 lb = 453.592 g, 1 oz = 28.3495 g

Using the Weight Converter API

TinyFn provides a dedicated endpoint for weight conversions:

API Request
GET https://api.tinyfn.io/v1/convert/weight
Headers: X-API-Key: your-api-key
Response
{
  "from_unit": "kg",
  "to_unit": "lb",
  "value": 75,
  "result": 165.347,
  "formula": "75 × 2.20462"
}

Parameters

Parameter Type Description
from string Source unit code (e.g., "kg")
to string Target unit code (e.g., "lb")
value number Value to convert

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/convert/weight?from=kg&to=lb&value=75',
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(data.result); // 165.347

Python

import requests

response = requests.get(
    'https://api.tinyfn.io/v1/convert/weight',
    params={'from': 'kg', 'to': 'lb', 'value': 75},
    headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(data['result'])  # 165.347

cURL

curl "https://api.tinyfn.io/v1/convert/weight?from=kg&to=lb&value=75" \
  -H "X-API-Key: your-api-key"

Common Use Cases

  • E-commerce: Display product weights in local units
  • Shipping: Calculate shipping costs based on weight
  • Health Apps: Track weight in user-preferred units
  • Recipe Apps: Convert ingredient weights
  • Fitness: Track lifting weights and body weight

Best Practices

  1. Know your audience: US users expect pounds, most others expect kg
  2. Handle precision: Use appropriate decimal places
  3. Store in metric: Store weights in kg internally, convert for display
  4. Validate ranges: Check for reasonable weight values

Try the Weight Converter API

Get your free API key and start converting weights in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key