This document provides suggested templates for REST-based APIs, for adoption by many of the services in CollectionSpace's services layer. This implements part of the work described in the "REST Service Contracts" section of Web Services - Paradigms and Contracts
This document is in process, and is currently incomplete. It has not yet been reviewed or accepted by the CollectionSpace Services Team. |
REST-based APIs, and their associated client-visible resource models, are suggested below for the three major types of CollectionSpace services: entity services, relation (association) services, and task services:
REST-based APIs for Entity Services
REST-based APIs for Relation (Association) Services
REST-based APIs for Task Services
Purpose
Retrieves a human-readable description of the service. This also verifies that the service exists, without interacting with the resources that it provides.
Request
GET /{resources_as_a_plural_noun}/description |
Request: Entity Body
The body of this request SHOULD be empty. If it is non-empty, the body will be ignored.
Response: Status Codes
Code |
Meaning |
Returned When |
---|---|---|
200 |
OK |
The description of the service was returned successfully. |
404 |
Not Found |
The resource at /{resources_as_a_plural_noun}/description does not exist. |
500 |
Internal Server Error |
A service error prevented the resource from begin returned. |
Response: Content-Type
Response: Entity Body (on Success)
Returns a human-readable description of the service: in plain text, in an XML format, or both, TBA. See Questions or Issues, below.
Response: Entity Body (on Error)
Returns an XML document containing a description of the error. See Common System Specific Elements for details.
As RESTful Service - Ajax Patterns notes, "Error responses should ... be in human-friendly language and with examples and hyperlinks."
Questions or Issues
Purpose
Retrieves the schema for the XML-based message payload that is exchanged in several of this service's operations.
Instance documents conforming to this schema may be exchanged in a variety of contexts. For instance, they may be:
Request
GET /{resources_as_a_plural_noun}/schema |
There will be only one schema returned per resource. If there may be typed resources, or child resources, available anywhere within the URL path, schemas for these resources can be retrieved via variations on this generic pattern, as in this example:
GET /{resources_as_a_plural_noun}/{typed_or_child_resources_as_a_plural_noun}/schema |
Request: Entity Body
The body of this request SHOULD be empty. If it is non-empty, the body will be ignored.
Response: Status Codes
Code |
Meaning |
Returned When |
---|---|---|
200 |
OK |
The schema was returned successfully. |
404 |
Not Found |
The resource at /{resources_as_a_plural_noun}/schema does not exist. |
500 |
Internal Server Error |
A service error prevented the resource from being returned. |
Response: Content-Type
application/xml (for schemas expressed in XML-based schema languages)
Response: Entity Body (on Success)
Returns the schema for the XML-based message payload that is exchanged in several of this service's operations.
By default, the schema will be declared in the W3C XML Schema language.
Response: Entity Body (on Error)
Returns an XML document containing a description of the error. See Common System Specific Elements for details.
Questions or Issues
Purpose
Creates a new resource of the specified type.
Request
POST /{resources_as_a_plural_noun} |
The RESTful metaphor is that of creating a new instance of the resource within a container of, or bucket of, resources of this type.
If there may be typed resources, or child resources, available anywhere within the URL path, new resources of that type can be created via variations on this generic pattern, as in this example:
POST /{resources_as_a_plural_noun}/{typed_or_child_resources_as_a_plural_noun} |
Request: Entity Body
If the service allows the client to supply the resource to be created:
The body of this request MUST contain a valid instance of an XML document, conforming to the schema used by the service.
If the service generates an instance of the resource algorithmically:
The body of this request SHOULD be empty. If it is non-empty, the body will be ignored.
Response: Status Codes
Code |
Meaning |
Returned When |
---|---|---|
201 |
Created |
A new instance of the resource was created successfully within /{resources_as_a_plural_noun}/schema. |
400 |
Bad Request |
The resource could not be created because the data sent in the entity body of the request was bad, as determined by the service. |
403 |
Not Authorized |
The resource could not be created because the client submitting the request was not authorized to create new resources in this container. |
500 |
Internal Server Error |
A service error prevented the resource from being created. |
Response: Content-Type
application/xml
Response: Entity Body (on Success)
Returns a representation of the newly-created resource, as an XML document conforming to the schema used by the service.
Response: Entity Body (on Error)
Returns an XML document containing a description of the error. See Common System Specific Elements for details.
Purpose
Reads (aka retrieves or returns) a representation of a specific instance of this resource.
Request
GET /{resources_as_a_plural_noun}/{resource_identifier} |
The {resource_identifier} is a value that uniquely identifies a particular resource. It may be an ID or some other type of identifier.
If there may be typed resources, or child resources, available anywhere within the URL path, these resources can be retrieved via variations on this generic pattern, as in this example:
GET /{resources_as_a_plural_noun}/{typed_or_child_resources_as_a_plural_noun}/{resource_identifier} |
Request: Entity Body
The body of this request SHOULD be empty. If it is non-empty, the body will be ignored.
Response: Status Codes
Code |
Meaning |
Returned When |
---|---|---|
200 |
OK |
A representation of the resource was returned successfully. |
403 |
Not Authorized |
The resource could not be returned because the client submitting the request was not authorized to read it. |
404 |
Not Found |
The resource at /{resources_as_a_plural_noun}/{resource_identifier} does not exist. |
500 |
Internal Server Error |
A service error prevented the resource from being read. |
Response: Content-Type
application/xml
Response: Entity Body (on Success)
Returns a representation of the requested resource, as an XML document conforming to the schema used by the service.
Response: Entity Body (on Error)
Returns an XML document containing a description of the error. See Common System Specific Elements for details.
Purpose
Reads (aka retrieves or returns) a list of 0 to n instances of this resource.
Depending on the query parameters submitted, the list may include either:
or
The default behavior is to return hyperlinks, each accompanied by the minimum information required to identify, in a human-readable format, their linked-to resources.
Request
GET /{resources_as_a_plural_noun} |
GET /{resources_as_a_plural_noun}?{optional_query_parameters ...} |
If there may be typed resources, or child resources, available anywhere within the URL path, these resources can be retrieved via variations on this generic pattern, as in these examples:
GET /{resources_as_a_plural_noun}/{typed_or_child_resources_as_a_plural_noun} |
GET /{resources_as_a_plural_noun}/{typed_or_child_resources_as_a_plural_noun}?{optional_query_parameters ...} |
A highly recommended child resource, for read (multiple) operations, will return a count of the numbers of records to be returned, as in this example:
GET /{resources_as_a_plural_noun}/count |
GET /{resources_as_a_plural_noun}/count?{optional_query_parameters ...} |
Query parameters
This section poses some hypothetical query parameters for initial discussion. The following examples are somewhat crude placeholders: |
Some possible examples of query parameters to modify read (multiple) requests. These in part come from Common System Specific Elements:
?orderby={information_unit}
Requests that hyperlinks or full records be returned in the natural sort order of a particular information unit (field). Defaults to ascending order if the sortorder query parameter isn't present.
sortorder={ascending|descending}
Specifies the sort order. Ignored if the orderby query parameter isn't also present.
?groupby={}
Specifies grouping of results. (Additional details TBA.)
?pagesize={nn} (or maxrecords=nn, etc.)
Return results with a maximum of nn items (hyperlinks or full records) returned per query.
?format={hyperlinks|full_records}
Requests that either hyperlinks or full records be returned. Defaults to hyperlinks.
Note that these query parameters may be combined; e.g. ?orderBy={information_unit}&pageSize={nn}
Request: Entity Body
The body of this request SHOULD be empty. If it is non-empty, the body will be ignored.
Response: Status Codes
Code |
Meaning |
Returned When |
---|---|---|
200 |
OK |
A list of the resources was returned successfully. |
400 |
Bad Request |
There was an error in the query parameters submitted with the request. |
403 |
Not Authorized |
A list of resources could not be returned because the client submitting the request was not authorized to read that list. |
404 |
Not Found |
The resource at /{resources_as_a_plural_noun} does not exist. |
500 |
Internal Server Error |
A service error prevented the list of resources from being read. |
Response: Content-Type
application/xml
Response: Entity Body (on Success)
Returns a representation of the requested resource, as an XML document conforming to the schema used by the service.
Response: Entity Body (on Error)
Returns an XML document containing a description of the error. See Common System Specific Elements for details.
Questions or Issues
Purpose
Completely updates in place (i.e. replaces) an existing resource of the specified type.
Request
PUT /{resources_as_a_plural_noun}/{resource_identifier} |
The {resource_identifier} is a value that uniquely identifies a particular resource. It may be an ID or some other type of identifier.
If there may be typed resources, or child resources, available anywhere within the URL path, resources of that type can be updated via variations on this generic pattern, as in this example:
PUT /{resources_as_a_plural_noun}/{typed_or_child_resources_as_a_plural_noun}/{resource_identifier} |
Request: Entity Body
The body of this request MUST contain a valid instance of an XML document, conforming to the schema used by the service.
Response: Status Codes
Code |
Meaning |
Returned When |
---|---|---|
200 |
OK |
A new instance of the resource was created successfully within /{resources_as_a_plural_noun}/schema. |
400 |
Bad Request |
The resource could not be updated because the data sent in the entity body of the request was bad, as determined by the service. |
403 |
Not Authorized |
The resource could not be updated because the client submitting the request was not authorized to update resources in this container. |
404 |
Not Found |
The resource at /{resources_as_a_plural_noun}/{resource_identifier} does not exist. |
500 |
Internal Server Error |
A service error prevented the resource from being updated. |
Response: Content-Type
application/xml
Response: Entity Body (on Success)
Returns a representation of the updated resource, as an XML document conforming to the schema used by the service.
Response: Entity Body (on Error)
Returns an XML document containing a description of the error. See Common System Specific Elements for details.
Questions or Issues
Two of several mechanisms through which we might facilitate partial (sparse) updates, noting that these mechanisms are not currently suggested here as patterns, include:
/\{resources_as_a_plural_noun\}/{resource_identifier}/\{information_unit_name\} |
Purpose
Deletes a specific instance of this resource.
Request
DELETE /{resources_as_a_plural_noun}/{resource_identifier} |
The {resource_identifier} is a value that uniquely identifies a particular resource. It may be an ID or some other type of identifier.
If there may be typed resources, or child resources, available anywhere within the URL path, resources of that type can be deleted via variations on this generic pattern, as in this example:
DELETE /{resources_as_a_plural_noun}/{typed_or_child_resources_as_a_plural_noun}/{resource_identifier} |
Request: Entity Body
The body of this request SHOULD be empty. If it is non-empty, the body will be ignored.
Response: Status Codes
Code |
Meaning |
Returned When |
---|---|---|
200 |
OK |
The resource was successfully deleted. |
403 |
Not Authorized |
The resource could not be deleted because the client submitting the request was not authorized to delete it. |
404 |
Not Found |
The resource at /{resources_as_a_plural_noun}/{resource_identifier} does not exist. |
500 |
Internal Server Error |
A service error prevented the resource from being updated. |
Response: Content-Type
application/xml
Response: Entity Body (on Success)
Returns a representation of the just-deleted resource, as an XML document conforming to the schema used by the service.
If the deletion occurred in error, or an 'undo' operation is desired, the client can use this representation to once again create the resource.
Response: Entity Body (on Error)
Returns an XML document containing a description of the error. See Common System Specific Elements for details.
This section is an in-process placeholder. The notes below are very rough at present. |
As RESTful Service - Ajax Patterns notes:
... REST will always have different interpretations. The ambiguity is exacerbated by the fact that there aren't nearly enough HTTP methods to support common operations. The most common example is the lack of a search method, meaning that different people will design search in different ways.
The two most widely used approaches to REST-based search that we have observed to date involve a) submitting a request containing query parameters, via GET and b) constructing and submitting a structure, via POST. Some variations on these approaches, both observed and hypothesized, include:
Also of interest:
Notes: Look at Lucene search syntax, as implemented in RESTful services.
Tim Bray wrote in 2003:
... there is rough consensus among search engines on what a query should look like: quotes mark "phrase searches", you use "+" to say a word must +occur and "-" to -exclude words. You URI-restrict searches like so: tbray.org:kirkby. Down the road, you might want to support something like XPath or even XQuery, but that would work fine through a Web interface too.
So a search engine would publicize a URI that you could use HTTP GET on to run searches; arguments would be q for the query, mr for maximum results, and ie for input-encoding. So a complete search request might look like:
q=%2busername:miso%20%2bhostname:miso.demo.sun.com%20%2bsubject:test |
To conduct a "simple" search using default assumptions ...
Query parameters:
query=
This section is an in-process placeholder. |
Follows the model of the Description operation for Entity Services.
This section is an in-process placeholder. |
For some potential patterns, see "Handling arbitrary actions" in RESTful Service - Ajax Patterns.
Follows the model of the Description operation for Entity Services.
RESTful Service - Ajax Patterns