Sign inSign up

nikfarjam/unit-converter-api-lightweight

By nikfarjam

•Updated about 1 month ago

An example unit conversion service that provides a RESTful API for converting between units.

Image
Web servers
0

2.8K

nikfarjam/unit-converter-api-lightweight repository overview

⁠Overview

This Docker image packages a lightweight, serverless RESTful API written in GoLang for converting between Celsius and Fahrenheit temperature units. It's designed for practicing deployments in serverless environments like Kubernetes, AWS Lambda, Google Cloud Functions, and Azure Functions.

⁠Key Features

  • Lightweight: Minimal dependencies and a small image size for fast startup and reduced resource consumption.
  • RESTful API: Provides a simple and intuitive API endpoint for temperature conversions.
  • GoLang: Built with GoLang for performance, efficiency, and concurrency.
  • Cloud-Native: Designed for easy integration with serverless platforms.
  • Well-Tested: Includes comprehensive unit tests to ensure reliability.

⁠How to Use

⁠Pull the Image

docker pull nikfarjam/unit-converter-api-lightweight:tagname

⁠Run the Container

docker run -it -p 9090:9090 nikfarjam/unit-converter-api-lightweight:tagname

This will start the API server on port 9090.

⁠API Endpoints
⁠POST /converter

Converts temperature between Celsius and Fahrenheit.

Request Body (JSON):

  • value: Number (temperature value)
  • from: "CELSIUS" or "FAHRENHEIT" (case-insensitive)
  • to: "CELSIUS" or "FAHRENHEIT" (case-insensitive)
⁠GET /version

Returns the current version of the API.

Response: Plain text version string (e.g., "v1.1.0")

Example:

curl http://localhost:9090/version
⁠Example curl commands

Convert Celsius to Fahrenheit:

curl -d '{ "value": 25, "from": "CELSIUS", "to": "FAHRENHEIT" }' http://localhost:9090/converter

Convert Fahrenheit to Celsius:

curl -d '{ "value": 77, "from": "FAHRENHEIT", "to": "CELSIUS" }' http://localhost:9090/converter

Invalid Unit (returns error):

Convert Celsius to Fahrenheit:

curl -d '{ "value": 25, "from": "CELSIUS", "to": "FAHRENHEIT" }' http://localhost:9090/converter

Convert Fahrenheit to Celsius:

curl -d '{ "value": 77, "from": "FAHRENHEIT", "to": "CELSIUS" }' http://localhost:9090/converter

Invalid Unit (returns error):

curl -v -d '{ "value": 20, "from": "Kelvin", "to": "Celsius" }' http://localhost:9090/converter
⁠Error Handling
  • If from or to is not "CELSIUS" or "FAHRENHEIT", the API returns HTTP 400 with an error message.
  • If the request body is malformed, the API returns HTTP 400.

Source Code: https://github.com/nikfarjam/unit-convertor-go⁠

License: Apache-2.0

Tag summary

Content type

Image

Digest

sha256:3c92ca380…

Size

8.5 MB

Last updated

8 months ago

docker pull nikfarjam/unit-converter-api-lightweight