This repository contains examples of how to use the Spring REST framework to implement an API which does some simple things:
- Say hello
- Tell the time of day
- Compute prime numbers and prime factors of a number
- Compute the Greatest Common Divisor (GCD) of two numbers
- Compute the Least Commonn Multiple (LCM) of two numbers
- Compute all Armstrong numbers in a given range (Note: Armstrong number (also known as Narcissistic numbers): An n-digit number equal to the sum of the nth powers of its digits.) Reference see http://mathworld.wolfram.com/NarcissisticNumber.html
- Compute all palindromic numbers in a given range (Note: A palindromic number is a number (in some base ) that is the same when written forwards or backwards.) Reference see http://mathworld.wolfram.com/PalindromicNumber.html
- Compute all amicable numbers in a given range (Note: Amicable numbers are two different numbers so related that the sum of the proper divisors of each is equal to the other number. (A proper divisor of a number is a positive factor of that number other than the number itself.) Reference see http://mathworld.wolfram.com/AmicablePair.html
- Compute all perfect numbers in a given range (Note: Perfect number, a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is 6, which is the sum of 1, 2, and 3.) Reference see http://mathworld.wolfram.com/PerfectNumber.html
NOTE: If you try to hit an invalid endpoint, the Spring controller advice will produce a nice error message indicating the endpoint is not in service.
- java 1.8
- maven 3.3 or higher
- git
- git clone https://github.com/jesimone57/spring_boot_rest_examples.git
- mvn clean compile test
- mvn spring-boot:run
- For best results, use Google Chrome and install the JSONView chrome plugin to nicely format JSON results. Firefox browser also does an excellent job of formatting the JSON results.
- Try any of the URLs below (Note: Spring Boot runs Tomcat server on localhost port 8080).
http://localhost:8080/swagger-ui.html
http://localhost:8080/hello/tom
http://localhost:8080/hello2?name=fred
http://localhost:8080/timeoftheday
http://localhost:8080/timeofthedayxml
http://localhost:8080/timeofthedayjson
http://localhost:8080/isprime/101
http://localhost:8080/isprime/100
http://localhost:8080/primes?start=3&end=101
http://localhost:8080/primes?start=10001&end=10099
http://localhost:8080/primefactors?start=3&end=101
http://localhost:8080/primefactors?start=10001&end=10099
http://localhost:8080/primefactors/100
http://localhost:8080/primefactors/1024
http://localhost:8080/gcd/30/45
hhttp://localhost:8080/lcm/10/15
http://localhost:8080/armstrongs?start=1&end=10000
http://localhost:8080/armstrongs?start=1&end=100000
http://localhost:8080/palindromes?start=0&end=100
http://localhost:8080/palindromes?start=100&end=1000
same as above with error checking on the range. Note: Error response if url parameters are missing or wrong.
http://localhost:8080/palindromes
http://localhost:8080/palindromes?start=-1&end=1000
http://localhost:8080/palindromes?start=100&end=q
http://localhost:8080/palindromes?start=10&end=1
http://localhost:8080/amicables?start=200&end=300
http://localhost:8080/amicables?start=1&end=100000