/quarkus-restful-temperature-converter

A simple demonstrative RESTful web service for temperature conversion developed with the Quarkus framework

Primary LanguageJavaMIT LicenseMIT

Quarkus RESTful Temperature Converter

The “Quarkus RESTful Temperature Converter” is a simple demonstrative application that exposes a RESTful web service for temperature conversion developed with Quarkus (the “Supersonic Subatomic” Java Framework).

The application currently supports 6 temperature units: Celsius – Fahrenheit – Kelvin – Rankine – Réaumur – Rømer

This project is exclusively developed by Andrea Binello (“andbin”).

License

This project is released under the MIT License, a very permissive free software license. See the full text of the license:

You can also see external resources like here or here.

How to build/run

The project requires at least:

  • a JDK 11 or later version
  • a very recent version of Maven (e.g. Maven 3.6.3 is ok)

Then you can build and run the application with:

mvn compile quarkus:dev

or using the Maven “wrapper” with:

mvnw compile quarkus:dev

REST API

The REST API is very simple and consists of only 4 endpoints. You can try and test the API using curl or Postman or any other similar tool.

🔹 Endpoint #1: Get all temperature units

→ GET http://host:port/temperatures

Example

curl http://localhost:8080/temperatures

Output (JSON):

[ {
  "code" : "celsius",
  "name" : "Celsius",
  "symbol" : "°C"
}, {
  "code" : "fahrenheit",
  "name" : "Fahrenheit",
  "symbol" : "°F"
},

    ......other units, truncated for brevity

]

🔹 Endpoint #2: Get temperature unit detail

→ GET http://host:port/temperatures/{unit}

Example 1

curl http://localhost:8080/temperatures/celsius

Output (JSON):

{
  "code" : "celsius",
  "name" : "Celsius",
  "symbols" : [ "°C" ],
  "waterFreezingPoint" : 0.0,
  "waterBoilingPoint" : 100.0,
  "namedAfter" : "Anders Celsius",
  "establishmentYear" : 1742
}

Example 2

curl http://localhost:8080/temperatures/rankine

Output (JSON):

{
  "code" : "rankine",
  "name" : "Rankine",
  "symbols" : [ "°R", "°Ra" ],
  "waterFreezingPoint" : 491.67,
  "waterBoilingPoint" : 671.67,
  "namedAfter" : "William John Macquorn Rankine",
  "establishmentYear" : 1859
}

🔹 Endpoint #3: Get temperature conversion

→ GET http://host:port/temperatures/{fromUnit}/{toUnit}/{value}?d={fractionalDigits}

Query param d is the number of fractional digits used for rounding the result. It can be a value from 0 to 7 and is optional (default value: 4).

Example

curl http://localhost:8080/temperatures/celsius/fahrenheit/32.7

Output (JSON):

{
  "from" : {
    "value" : 32.7,
    "name" : "Celsius",
    "symbol" : "°C"
  },
  "to" : {
    "value" : 90.86,
    "name" : "Fahrenheit",
    "symbol" : "°F"
  }
}

🔹 Endpoint #4: Get temperature conversions

→ GET http://host:port/temperatures/{fromUnit}/others/{value}?d={fractionalDigits}

Query param d is the number of fractional digits used for rounding the result. It can be a value from 0 to 7 and is optional (default value: 4).

Example

curl http://localhost:8080/temperatures/celsius/others/32.7

Output (JSON):

{
  "from" : {
    "value" : 32.7,
    "name" : "Celsius",
    "symbol" : "°C"
  },
  "to" : [ {
    "value" : 90.86,
    "name" : "Fahrenheit",
    "symbol" : "°F"
  }, {
    "value" : 305.85,
    "name" : "Kelvin",
    "symbol" : "K"
  },

      ......other units, truncated for brevity

  ]
}

Notes on temperature units specified in urls

In path templates you can use the full code/name (lower case) of a temperature unit or any possible abbreviation (prefix):

http://localhost:8080/temperatures/celsius
http://localhost:8080/temperatures/celsiu
http://localhost:8080/temperatures/celsi
http://localhost:8080/temperatures/cels
http://localhost:8080/temperatures/cel

etc... are all OK. The important thing is that there is no ambiguity between multiple temperature units!