+

Search Tips   |   Advanced Search

Define the resources in RESTful applications

RESTful services are based on manipulating resources. Resources can contain static or dynamically updated data. We define resources in applications, and make them available as REST services.

Consider the case of an application defined to support a book store. This application currently has a database with several tables that define the various items in the collection of books and the inventory of each book. In this example, there are a number of ways to represent the data in the database in a RESTful application. One approach is to consider each table as an individual resource, so that each of the verbs in the RESTful request maps to actions the database supports on that table such as select, insert, update, delete. There are URL patterns for resources, resource methods, HTTP headers and response codes, media types, and parameters for request representations to resources

In support of this database for the book store application, there might already be existing code responsible for accessing the database and retrieving data from tables. Even though the rows in each of the tables logically represent each resource, the accessor classes are used to define the resources.

Alternately, we might have static content that does not reside in a database. Whether it is a collection of documents in various formats or a resource-based facade for other remote systems, when using JAX-RS, we can distribute content from multiple sources.

Examples of a resource from an online book store application include a book, an order from a store, and a collection of users.

Resources are addressable by URLs. HTTP methods can perform operations on resources. Resources use formats such as XML and JSON. We can use HTTP headers and parameters to pass extra information relevant to the request and response.

We can annotate existing or new Plain Old Java objects. Annotated resource classes and methods are started depending on the URI patterns.

  1. Identify the types of resources in the application.

  2. Optional. Identify existing Java classes to use as resource classes.

  3. Create new Java classes for resources that do not have an existing Java class.


What to do next

Based on the resources that we have defined, read about defining URL patterns for resources, resource methods, HTTP headers and response codes, media types, and parameters for request representations to resources to learn more about additional steps we can take to define the resources for the JAX-RS application.


Related concepts

  • Overview of Java API for RESTful Web Services (JAX-RS)


    Related tasks

  • Define the URI patterns for resources in RESTful applications
  • Define resource methods for RESTful applications
  • Define the HTTP headers and response codes for RESTful applications
  • Define parameters for request representations to resources in RESTful applications
  • Define media types for resources in RESTful applications
  • Implement JAX-RS web applications