Welcome to teslazonda's temperature API. This API takes a temperature as input and converts the input to another unit. Both Fahrenheit -> Celsius and Celsius -> Fahrenheit conversions are possible.
- Navigate to the project directory
- Run
bundle installto install Ruby gems. - Run
rails sin the project directory to start the server
The Rails application will run by default on port 3000. The following URL can be used to test the application locally: http://localhost:3000/v1/convert_temperature
-H 'Content-Type: application/json'
{
"temperature: float,
"unit": "string"
}
Note: The unit must either be "Celsius" or "Fahrenheit".
Successful curl request
curl -X POST -H "Content-Type: application/json" -d '{"temperature": 100, "unit": "Celsius"}' http://localhost:3000/v1/convert_temperatureSample response
{"temperature":100.0,"unit":"Celsius","converted_temperature":212.0,"converted_unit":"Fahrenheit"}Input temperature is less than absolute zero
curl -X POST -H "Content-Type: application/json" -d '{"temperature": -300, "unit": "Celsius"}' http://localhost:3000/v1/convert_temperatureSample response
{"error":"Temperature below absolute zero is not possible"}Bad Request
curl -X POST -H "Content-Type: application/json" -d '{"Bad Request"}' http://localhost:3000/v1/convert_temperatureSample response
{"error":"An error occurred: Error occurred while parsing request parameters"}- Run
bundle exec rspecto run unit tests