Proper CRUD

I used the following page as a guide:
Creating a CRUD App in Minutes with Angular's $resource

The basic principles discussed in the article are similar to Ruby On Rails standards.

Here is also another site I used as a reference: HTTP Methods for RESTful Services


Proper CRUD - Project Code Points

Unrelated to CRUD operations, in my project, I created this as a base abstract class:

public abstract class ObjectAbstract {

    @Override
    public boolean equals(final Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj);
    }

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
    }

    @Override
    public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}

I tend not to use too many base classes and favor composition over inheritance, but creating an abstract class from which my model/bean classes extend seems reasonable. The built-in Java toString, hashCode, and equals methods tend to not be useful in practical coding. The one major disadvantage of doing this is that the Apache Commons Lang library uses reflection. In a sense, I am trading off clean code for efficiency.

I also included dependency injection in the project. I am familiar with Spring DI, and the point of this project is to learn something new. So, I went with a new framework. I Google searched a bit and chose Google Guice over Java CDI (both versions are used at Explorys). Even though Java CDI is a "standard" now, it seems Guice is more widely used and accepted across the community.

Google Guice Dependency Injection Example Tutorial

I only used some real simple examples, but would like to take some time eventually and go through an advanced tutorial.

<dependency>
    <groupId>com.google.inject</groupId>
    <artifactId>guice</artifactId>
    <version>3.0</version>
</dependency>

I had to switch from Tomcat to JBoss (WildFly 8.2). Project configuration can be done to allow Tomcat to use dependency injection (Weld).

I like to subscribe to the idea of dumb resources. Resources should simply be interfaces to internally exposed validators and agents (managers). Once a purposeful action is performed, an appropriate result should be returned.

Project Highlights

- Uses annotations for configuration
    - No need for a web.xml
- REST Client
    - Jersey
    - com.sun.jersey : v1.19
- Dependency Injection
    - Google Guice
    - com.google.inject : guice : v3.0
- Commons Lang
    - org.apache.commons : commons-lang3 : v3.3.2
- Logging
    - Log4j
    - org.apache.logging.log4j : v2.1

I put the project up on GitHub:
GitHub - RESTfulCRUDDev3l

I have the project deployed on my personal OpenShift server:

CURL Commands to exercise CRUD operations

  • GET
    curl http://services-dev3l.rhcloud.com/RESTfulCRUDDev3l/user
  • GET by ID
    curl http://services-dev3l.rhcloud.com/RESTfulCRUDDev3l/user/{id}
  • POST
    curl -X POST http://services-dev3l.rhcloud.com/RESTfulCRUDDev3l/user \
    -H "Content-Type: application/json" \
    -d '{"userName":"user_name","email":"email@email.com","status":"AC","password":"password"}'
  • PUT
    curl -X PUT http://services-dev3l.rhcloud.com/RESTfulCRUDDev3l/user/{id} \
    -H "Content-Type: application/json" \
    -d '{"id":{id},"userName":"user_name","email":"email@email.com","status":"AC","password":"password"}'
  • DELETE
    curl -X DELETE http://services-dev3l.rhcloud.com/RESTfulCRUDDev3l/user/{id}

Get In Touch

We'd love to hear from you! Whether you have a question about our services, need a consultation, or just want to connect, our team is here to help. Reach out to us through the form, or contact us directly via social media.


Previous
Previous

Definition of Done

Next
Next

Defect Definition of Ready