Just as ResourceQuery makes Query's API available for remote access, so does ResourceHome for the Home component. The following table describes how the two APIs (HTTP and Home) are bound together.
Table 23.1. Bindings in ResourceHome
| HTTP method | Path | Function | ResourceHome method |
|---|---|---|---|
| GET | {path}/{id} | Read | getResource() |
| POST | {path} | Create | postResource() |
| PUT | {path}/{id} | Update | putResource() |
| DELETE | {path}/{id} | Delete | deleteResource() |
- You can GET, PUT, and DELETE a particular user instance by sending HTTP requests to /user/{userId}
- Sending a POST request to
/usercreates a new user entity instance and persists it. Usually, you leave it up to the persistence layer to provide the entity instance with an identifier value and thus an URI. Therefore, the URI is sent back to the client in theLocationheader of the HTTP response.
The configuration of ResourceHome is very similar to ResourceQuery except that you need to explicitly specify the underlying Home component and the Java type of the entity identifier property.
<resteasy:resource-home path="/user" name="userResourceHome" entity-home="#{userHome}" entity-id-class="java.lang.Integer"/>
Again, you can write a subclass of ResourceHome instead of XML:
@Name("userResourceHome") @Path("user") public class UserResourceHome extends ResourceHome<User, Integer> { @In private EntityHome<User> userHome; @Override public Home<?, User> getEntityHome() { return userHome; } }
For more examples of ResourceHome and ResourceQuery components, take a look at the Seam Tasks example application, which demonstrates how Seam/RESTEasy integration can be used together with a jQuery web client. In addition, you can find more code example in the Restbay example, which is used mainly for testing purposes.