yegor256 / requs

Controlled Natural Language for Requirements Specifications
https://www.requs.org
Other
39 stars 5 forks source link

Bad design in REST method #106

Closed amihaiemil closed 8 years ago

amihaiemil commented 8 years ago

Method post(...) currently returns a simple String on success and throws exception on failure.

It should always return a Response object with appropriate status. Also, we can get rid of "NotNull" annotation and replace it with DefaultValue("") (maybe check for empty string and return a Response with 412 status?)

Thus, on success it would

    return Response.ok().entity(
             Json.createObjectBuilder()
                .add("spec", xml.nodes("/spec").get(0).toString())
                .add("html", xsl.applyTo(xml))
                .build().toString()
    ).build();

and on error it would

    return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR)
                    .entity(ExceptionUtils.getStackTrace(ex))
                    .build();
davvd commented 8 years ago

@yegor256 please take a look at it and dispatch (see par.21)

amihaiemil commented 8 years ago

@yegor256 ping

amihaiemil commented 8 years ago

@yegor256 ping

yegor256 commented 8 years ago

@amihaiemil I don't see why returning a String is bad. JAX-RS recommends to do it this way. it's simpler.