Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "REST support in STP"
Line 19: | Line 19: | ||
[[Image:Connect.JPG]] | [[Image:Connect.JPG]] | ||
− | ====select tables from the databse and click finish button==== | + | ====select tables that want to be exposed as REST resource from the databse and click finish button==== |
[[Image:Tables.JPG]] | [[Image:Tables.JPG]] | ||
Line 31: | Line 31: | ||
[[Image:Jpa_detail.JPG]] | [[Image:Jpa_detail.JPG]] | ||
+ | add all entity classes into a persistence unit by configuring persistence.xml | ||
==3. Generate Resources class for each entity class== | ==3. Generate Resources class for each entity class== | ||
+ | In order to expose entity classes to resources, we will wrap each entity class as rest resource by two Resources class with annotation, | ||
+ | for example, Item.class is wraped by ItemResource.class and ItemsResource.class. ItemsResource.class is to expose a uri to get Item | ||
+ | list, and ItemResource.class is for getting a Item detail infomation. |
Revision as of 03:33, 7 November 2007
Contents
Introduction
This page aims to define the basic processes on how to support REST in stp, there is sample to simplifies how to create a RESTfull service from a database directly.
There are two ways to support to create RESTfull service:
* Exposing a database to RESTfull service directly * Starting from importing some POJO class into a rest project
Exposing a database to RESTfull service directly
We can create a RESTfull service by starting from a database with the following steps:
1. Create a REST project using STP.Service Creation Wizard
add project nature "org.eclipse.jem.workbench.JavaEMFNature" which defined in WTP DALI subproject and Java Persistence Facet, once the project has the nature and JP Facet, some DALI function will be available in the subsequent steps.
2. Generate Entity classes from database
select a database to connect
select tables that want to be exposed as REST resource from the databse and click finish button
the following classes will be generated:
three entities class will be generated, these classes are annotated with JPA annotations(by the way, the used JPA implementation library is Oracle TopLink), users can modify the annotations in the generated classes through JPA detail view, it looks like:
add all entity classes into a persistence unit by configuring persistence.xml
3. Generate Resources class for each entity class
In order to expose entity classes to resources, we will wrap each entity class as rest resource by two Resources class with annotation, for example, Item.class is wraped by ItemResource.class and ItemsResource.class. ItemsResource.class is to expose a uri to get Item list, and ItemResource.class is for getting a Item detail infomation.