Coder Social home page Coder Social logo

andbin / quarkus-restful-temperature-converter Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 56 KB

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

License: MIT License

Java 100.00%
java quarkus restful

quarkus-restful-temperature-converter's Introduction

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!

quarkus-restful-temperature-converter's People

Contributors

andbin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.