[forge-issues] [JBoss JIRA] (FORGE-1273) REST NOT_FOUND should be NO_CONTENT

Vineet Reynolds (JIRA) jira-events at lists.jboss.org
Mon Oct 21 11:00:03 EDT 2013


    [ https://issues.jboss.org/browse/FORGE-1273?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12823631#comment-12823631 ] 

Vineet Reynolds commented on FORGE-1273:
----------------------------------------

Hey [~agoncal],

     I'm not sure a 204 (or any 2xx response code) would be in line with other REST APIs that I've studied. The 204 would indicate that everything is correct, while the 404 would indicate that the client performed an incorrect operation by requesting the representation for a resource that doesn't exist.

     I hope this convinces you. If not I'll appeal to a higher authority :) I'll be looking at error mapping shortly, and one of the small changes I intend to make it easier for the generated REST APIs to provide information about errors. I'm using [this article from ApiGee|https://blog.apigee.com/detail/restful_api_design_what_about_errors] as a guideline (can be ignored though where convenient), and I think we'd find it difficult to convince end-users to map missing resource exceptions to a 204.

    By the way, many thanks for bringing all this up. Not only does this serve as a review, it also ensures that design decisions like these are captured somewhere. Of course, when we have better site documentation, this would automatically find it's place there.
                
> REST NOT_FOUND should be NO_CONTENT
> -----------------------------------
>
>                 Key: FORGE-1273
>                 URL: https://issues.jboss.org/browse/FORGE-1273
>             Project: Forge
>          Issue Type: Enhancement
>          Components: Scaffold
>    Affects Versions: 1.4.2.Final
>            Reporter: Antonio Goncalves
>             Fix For: 2.x Future
>
>
> Hi,
> In the REST endpoint generated code we have the following methods that return a Status.NOT_FOUND status in case the entity is not found : 
> {code}
>    @DELETE
>    @Path("/{id:[0-9][0-9]*}")
>    public Response deleteById(@PathParam("id") Long id)
>    {
>       Book entity = em.find(Book.class, id);
>       if (entity == null)
>       {
>          return Response.status(Status.NOT_FOUND).build();
>       }
>       em.remove(entity);
>       return Response.noContent().build();
>    }
>    @GET
>    @Path("/{id:[0-9][0-9]*}")
>    @Produces("application/xml")
>    public Response findById(@PathParam("id") Long id)
>    {
>       TypedQuery<Book> findByIdQuery = em.createQuery("SELECT DISTINCT b FROM Book b WHERE b.id = :entityId ORDER BY b.id", Book.class);
>       findByIdQuery.setParameter("entityId", id);
>       Book entity;
>       try
>       {
>          entity = findByIdQuery.getSingleResult();
>       }
>       catch (NoResultException nre)
>       {
>          entity = null;
>       }
>       if (entity == null)
>       {
>          return Response.status(Status.NOT_FOUND).build();
>       }
>       return Response.ok(entity).build();
>    }
> {code}
> In both cases it should be a Status.NO_CONTENT. The resource exists (otherwise it would have been impossible to invoke it) it just happens that it returns an empty body (with a no content status)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the forge-issues mailing list