Skip to content

Instantly share code, notes, and snippets.

@danielshaya
Created March 9, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielshaya/b969e37e056273c67032 to your computer and use it in GitHub Desktop.
Save danielshaya/b969e37e056273c67032 to your computer and use it in GitHub Desktop.
Rest Calculator
package example;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
@Path("calculator")
public class Calculator {
@GET
@Path("squareRoot")
@Produces(MediaType.APPLICATION_JSON)
public Result squareRoot(@QueryParam("input") double input){
Result result = new Result("Square Root");
result.setInput(input);
result.setOutput(Math.sqrt(result.getInput()));
return result;
}
@GET
@Path("square")
@Produces(MediaType.APPLICATION_JSON)
public Result square(@QueryParam("input") double input){
Result result = new Result("Square");
result.setInput(input);
result.setOutput(result.getInput()*result.getInput());
return result;
}
static class Result{
double input;
double output;
String action;
public Result(){}
public Result(String action) {
this.action = action;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public double getInput() {
return input;
}
public void setInput(double input) {
this.input = input;
}
public double getOutput() {
return output;
}
public void setOutput(double output) {
this.output = output;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment