With Spark Java if I want a GET request, it's just a matter of adding a call like this, there's no separate client or server implementation needed.
...
public static void main(String[] args) throws FISException {
port(9091);
Spark.staticFileLocation("/public");
get("/product/id/:id", (rq, rs) -> new ProductList().getInstance().getProductsById(rq.params(":id")));ProductList.getProductsById() can implement however you want to fetch the list of products, then convert to pretty JSON using this.
Gson gson = new GsonBuilder().setPrettyPrinting().create();
productJson = "<pre>" + gson.toJson(productList) + "</pre>";
No annotation hell as in JAX-RS. Why hasn't someone looked into this already? :D
Corresponding JAX-RS implementation looks like this:
@Path("/product")
@io.swagger.annotations.Api(description = "the product API")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2016-02-18T19:04:14.810Z")
public class ProductApi {
private final ProductApiService delegate = ProductApiServiceFactory.getProductApi();
@GET
@Path("/{id}")
@io.swagger.annotations.ApiOperation(value = "", notes = "", response = void.class, tags={ })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "Get product details", response = void.class) })
public Response productIdGet(
@ApiParam(value = "ID",required=true) @PathParam("id") String id,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.productIdGet(id,securityContext);
}
}
What am I missing?