Rest API Dspace
Rest API Dspace
Rest API Dspace
The REST API module provides a programmatic interface to DSpace Communities, Collections, Items,
and Bitstreams.
DSpace 4 introduced the initial REST API, which did not allow for authentication, and provided only
READ-ONLY access to publicly accessible Communities, Collections, Items, and Bitstreams. DSpace
5 builds off of this and allows authentication to access restricted content, as well as allowing Create,
Edit and Delete on the DSpace Objects. DSpace 5 REST API also provides improved pagination over
resources and searching. There has been a minor drift between the DSpace 4 REST API and the
DSpace 5 REST API, so client applications will need to be targeted per version.
In DSpace 4, the initial/official Jersey-based REST API was added to DSpace. The DSpace 4 REST
API provides READ-ONLY access to DSpace Objects.
In DSpace 5, the REST API adds authentication, allows Creation, Update, and Delete to objects, can
access restricted materials if authorized, and it requires SSL.
Disabling SSL
For localhost development purposes, SSL can add additional getting-started difficulty, so security can
be disabled. To disable DSpace REST's requirement to require security/ssl, alter
[dspace]/webapps/rest/WEB-INF/web.xml
or
[dspace-source]/dspace-rest/src/main/webapp/WEB-INF/web.xml
and comment out the <security-constraint> block, and restart your servlet container.
Production usages of the REST API should use SSL, as authentication credentials should not go over
the internet unencrypted.
REST Endpoints
The REST API is modeled after the DSpace Objects of Communities, Collections, Items, and
Bitstreams. The API is not a straight database schema dump of these entities, but provides some
wrapping that makes it easy to follow relationships in the API output.
HTTP Header: Accept
Note: You must set your request header's "Accept" property to either JSON (application/json) or XML
(application/xml) depending on the format you prefer to work with.
Example usage from command line in XML format with pretty printing:
curl -s -H "Accept: application/xml" http://localhost:8080/rest/communities | xmllint --format -
Example usage from command line in JSON format with pretty printing:
curl -s -H "Accept: application/json" http://localhost:8080/rest/communities | python -m json.tool
For this documentation, we will assume that the URL to the "REST" webapp will
be http://localhost:8080/rest/ for production systems, this address will be slightly different, such as:
https://demo.dspace.org/rest/. The path to an endpoint, will go after the /rest/, such as
/rest/communities, all-together this is: http://localhost:8080/rest/communities
Another thing to note is that there are Query Parameters that you can tack on to the end of an endpoint
to do extra things. The most commonly used one in this API is "?expand". Instead of every API call
defaulting to giving you every possible piece of information about it, it only gives a most commonly
used set by default and gives the more "expensive" information when you deliberately request it. Each
endpoint will provide a list of available expands in the output, but for getting started, you can start with
?expand=all, to make the endpoint provide all of its information (parent objects, metadata, child
objects). You can include multiple expands, such as: ?expand=collections,subCommunities .