The configuration of the REST API consists in the deployment of jar libraries to the classpath
and the configuration of the servlet in the
/WEB-INF/web.xml
. After it's configured,
all persistent classes are automatically exposed via RESTful HTTP interface. You need to have
enhanced versions of the model classes in the CLASSPATH.
DataNucleus REST API requires the libraries:
datanucleus-core
,
datanucleus-api-rest
,
datanucleus-api-jdo
,
jdo-api
, as well as
datanucleus-rdbms
(or whichever
datastore you wish to persist to if not RDBMS).
You would also require JPA API jar if using JPA metadata (XML/annotations) in your model classes.
In WAR files, these libraries are deployed under the folder
/WEB-INF/lib/
.
The DataNucleus REST Servlet class implementation is
org.datanucleus.api.rest.RestServlet
.
It has to be configured in the
/WEB-INF/web.xml
file, and it takes one initialisation parameter.
|
Parameter
|
Description
|
|
persistence-context
|
Name of a PMF (if using
jdoconfig.xml
), or the name of a
persistence-unit (if using
persistence.xml
) accessible to the servlet
|
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>DataNucleus</servlet-name>
<servlet-class>org.datanucleus.api.rest.RestServlet</servlet-class>
<init-param>
<param-name>persistence-context</param-name>
<param-value>myPMFName</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DataNucleus</servlet-name>
<url-pattern>/dn/*</url-pattern>
</servlet-mapping>
...
</web-app>
changing
myPMFName
to the name of your PMF, or the name of your persistence-unit, and changing
dn/*
to the URL pattern where you want DataNucleus REST API calls to be answered.
|