Unit Conversion API

Back to Portfolio

Go to Unit Conversion API
Overview

The Unit Conversion API allows users to convert values between units across four main categories: length, mass, temperature, and time. Whether converting meters to feet or Celsius to Fahrenheit, this API offers precise and seamless conversions through simple JSON-based requests. Users can submit conversion requests by providing the category, original unit, target unit, and value. The API responds in real-time and also stores the last 10 conversions for easy retrieval. Built with Django REST Framework, the API is scalable and performs efficiently, even during high traffic.

Error handling ensures inputs are valid, with detailed messages guiding users to provide correct units. Rate-limiting is in place to ensure fairness, allowing authenticated users up to 10 requests per minute and anonymous users 5 requests per minute. The Unit Conversion API is perfect for applications needing quick and accurate conversions, whether in scientific, engineering, or everyday contexts, with room for future expansion to more categories and units.


How to Use the API

Below are the available API endpoints and their usage:

Endpoint Method Description
/api/units/ GET Retrieve the last 10 conversion results stored in the session.
/api/units/ POST Submit a conversion request. The payload should include the category (length, mass, temperature, time), the numeric value, the original unit, and the conversion unit.
Example Usage

To convert units, you can make a POST request to /api/units/ with the following JSON payload:

{
    "category": "length",
    "value": 100,
    "original_unit": "meters",
    "conversion_unit": "feet"
}

The response will return the converted value:

{
    "category": "length",
    "value": 100,
    "original_unit": "meters",
    "conversion_unit": "feet",
    "converted_value": 328.084
}
Supported Categories and Units

The API supports the following categories and units:

  • Length: meters, kilometers, centimeters, millimeters, inches, feet, yards, miles.
  • Mass: kilograms, grams, milligrams, pounds, ounces, stones.
  • Temperature: celsius, fahrenheit, kelvin.
  • Time: seconds, minutes, hours, days, weeks, years.
Custom Throttling Rules

The API is rate-limited to prevent excessive requests. Throttling is applied on a per-user basis, with burst throttling enabled to handle short bursts of requests.

Handling Errors

If the conversion request contains invalid data, the API will return an error message. Here are some common error responses:

  • Invalid category: {"error": "Unknown category: some_category"}
  • Invalid units: {"error": "Unknown original_unit: some_unit for category length"}

Example Screenshots

Video Overview
Go to Unit Conversion API