WAS v8.5 > Develop applications > Develop web services - RESTful services > Planning JAX-RS web applicationsDefine the resources in RESTful applications
We can use Java API for RESTful Web Services (JAX-RS) to develop services that follow REST principles. RESTful services are based on manipulating resources. Resources can contain static or dynamically updated data. By identifying the resources in the application, we can make the service more useful and easier to develop.
After we have identified the application to expose as a RESTFUL service, first define the resources for the RESTful application. When defining the resources for the application, consider the type of data do to expose. Perhaps you already have a relational database containing information to expose to users using REST technology. Do you already have a set of Java classes defined for accessing that data?
For example, 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 the actions the database supports on that table such as select, insert, update, delete. This example is a simple approach to creating a RESTful application. This approach using the book store example is also used in the documentation that describes defining 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 that is responsible for accessing the database and retrieving the data from each table. Even though the rows in each of the tables logically represents each resource, the accessor classes are used to define the resources. The implementing JAX-RS applications documentation provides more details on how these classes are incorporated into your JAX-RS application.
Alternately, you might have more static content that does not reside in a database to distribute as resources. Whether it is a collection of documents in various formats or a resource-based facade for other remote systems, using JAX-RS, we can distribute content from multiple sources. Resources are the basic building block of a RESTful service. 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 and HTTP methods can perform operations on resources. Resources can have multiple representations using different formats such as XML and JSON. We can use HTTP headers and parameters to pass additional information that is relevant to the request and response.
With JAX-RS, we can annotate existing or new Plain Old Java objects (POJO) with JAX-RS specific annotations. JAX-RS annotated resource classes and the annotated methods are invoked depending on the URI patterns. We can use the annotated resource classes after these resource classes are added to the list of resources returned by the overridden methods in the JAX-RS application class.
- Identify the types of resources in the application.
- (optional) Identify existing Java classes that we can use as resource classes.
- Create new Java classes for resources that do not have an existing Java class.
Results
You have defined the content to expose as a collection of resources in the application.
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 IBM JAX-RS
Related
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