Skip to content

Collection Resources

Collection resources in RESTful web services represent groups of related entities of the same type. They serve as containers for managing multiple individual resources through a unified interface.

  • Plural naming: Always use plural nouns (e.g., /species, /plantes)
  • Uniform operations: Support standard CRUD operations across all items
  • Pagination support: Handle large datasets efficiently
  • Filtering capabilities: Allow clients to retrieve specific subsets

Collection resources are identified by URIs that represent logical groupings of similar entities. For instance, /customers represents all customer resources within the system.

Collection resource names must be plural nouns (e.g., /species, /planets, /galaxies). This naming convention clearly distinguishes collections from individual singleton resources.

Best Practices:

  • Use lowercase with hyphens for multi-word resources: /stellar-objects
  • Avoid abbreviations: prefer /species over /spc
  • Keep names intuitive and domain-specific

Refer to our REST principles for comprehensive naming guidelines.

Retrieving collections is typically the most frequently used operation. Collections should support pagination, filtering, and sorting to handle real-world datasets efficiently.

GET /{namespace}/{version}/{resource}?page={page}&limit={limit}&sort={field}&filter={criteria}
http
ParameterDescriptionExample
pagePage number (1-based)?page=2
limitItems per page (default: 20)?limit=50
sortSort field with direction?sort=name:asc
filterFilter criteria?filter=status:active
GET /astrobiology/v1/species?page=1&limit=20&sort=scientific_name:asc&filter=habitat:aquatic
http

HAL (Hypertext Application Language) response format with enhanced metadata:

{
"_links": {
"self": { "href": "{baseurl}/species?page=1&limit=20&filter=habitat:aquatic" },
"first": { "href": "{baseurl}/species?page=1&limit=20&filter=habitat:aquatic" },
"last": { "href": "{baseurl}/species?page=8&limit=20&filter=habitat:aquatic" },
"next": { "href": "{baseurl}/species?page=2&limit=20&filter=habitat:aquatic" },
"prev": null,
"find": { "href": "{baseurl}/species{?id}", "templated": true }
},
"page": 1,
"limit": 20,
"total_pages": 8,
"total_count": 156,
"has_more": true,
"_embedded": {
"species": [
{
"_links": {
"self": { "href": "{baseurl}/species/SPX-AQUA-001" }
},
"id": "SPX-AQUA-001",
"scientific_name": "Hydrozoa stellaris",
"common_name": "Stellar Jellyfish",
"habitat": "aquatic",
"planet_origin": "Kepler-442b",
"discovered_date": "2157-03-15T10:30:00Z"
},
{
"_links": {
"self": { "href": "{baseurl}/species/SPX-AQUA-002" }
},
"id": "SPX-AQUA-002",
"scientific_name": "Cephalopoda cosmicus",
"common_name": "Cosmic Octopus",
"habitat": "aquatic",
"planet_origin": "Europa",
"discovered_date": "2159-07-22T14:45:00Z"
}
]
}
}
json
Status CodeScenarioResponse Body
200 OKSuccessful retrievalCollection with items or empty array
400 Bad RequestInvalid query parametersError details
401 UnauthorizedAuthentication requiredError message
403 ForbiddenAccess deniedError message
500 Internal Server ErrorServer errorError details

Important Notes:

  • Empty collections return 200 OK with "total_count": 0, never 404 Not Found
  • Invalid pagination parameters (e.g., page=0) should return 400 Bad Request
  • Include helpful error messages for debugging

Individual resources typically contain more detailed information than their collection counterparts. These resources are accessed through their unique identifiers within the collection context.

GET operations must be idempotent—they should never modify system state and must return consistent results across multiple requests.

Resource identifiers for sensitive entities (customers, users) should be non-sequential and preferably non-numeric to prevent enumeration attacks.

When resources serve as references in other contexts, use immutable string identifiers for improved readability and debugging capabilities (e.g., “USER_ADMIN_ROLE” rather than “1421321”).

GET /{namespace}/{version}/{resource}/{resource-id}
http
GET /astrobiology/v1/species/SPX-TERR-004
Accept: application/json
Authorization: Bearer {token}
http
{
"_links": {
"self": { "href": "{baseurl}/species/SPX-TERR-004" },
"collection": { "href": "{baseurl}/species" },
"edit": { "href": "{baseurl}/species/SPX-TERR-004" },
"delete": { "href": "{baseurl}/species/SPX-TERR-004" },
"planet": { "href": "{baseurl}/planets/MARS" }
},
"id": "SPX-TERR-004",
"scientific_name": "Bacillus martianus",
"common_name": "Martian Rock Bacteria",
"classification": {
"kingdom": "Bacteria",
"phylum": "Firmicutes",
"class": "Bacilli"
},
"habitat": "terrestrial",
"planet_origin": "Mars",
"temperature_range": {
"min_celsius": -80,
"max_celsius": 15
},
"discovered_date": "2156-12-03T08:22:00Z",
"last_updated": "2159-03-01T09:15:00Z"
}
json
Status CodeScenario
200 OKResource found and returned
404 Not FoundResource ID doesn’t exist
401 UnauthorizedAuthentication required
403 ForbiddenAccess denied for this resource
410 GoneResource was deleted (optional)

Updates a complete resource using the PUT method. The request payload structure should match the GET response format for the same resource. System-generated fields (e.g., create_time, last_modified) may be omitted or ignored during processing.

PUT /{namespace}/{version}/{resource}/{resource-id}
http
PUT /astrobiology/v1/species/SPX-TERR-004
Content-Type: application/json
Authorization: Bearer {token}
{
"id": "SPX-TERR-004",
"scientific_name": "Bacillus martianus extremus",
"common_name": "Extreme Martian Rock Bacteria",
"habitat": "terrestrial",
"temperature_range": {
"min_celsius": -95,
"max_celsius": 25
}
}
http
Status CodeScenarioResponse
204 No ContentSuccessful updateEmpty body
400 Bad RequestValidation errors, read-only field modificationError details
404 Not FoundResource doesn’t existError message
409 ConflictConcurrent modification detectedConflict details
422 Unprocessable EntityBusiness logic failuresError details with field-level validation

Example Error Response (400 Bad Request):

{
"error": {
"code": "VALIDATION_FAILED",
"message": "Species data validation failed",
"details": [
{
"field": "temperature_range.min_celsius",
"code": "INVALID_RANGE",
"message": "Minimum temperature cannot exceed maximum temperature"
},
{
"field": "scientific_name",
"code": "REQUIRED_FIELD",
"message": "Scientific name is required for species classification"
}
]
}
}
json
Partial update support is optional and implementation-dependent.
Section titled “Partial update support is optional and implementation-dependent.”

PATCH operations modify specific fields of a resource without affecting unchanged properties. Unlike PUT operations, PATCH requests only need to include the fields being updated.

The HTTP PATCH method follows RFC 7386: JSON Merge Patch specifications.

Return 204 No Content with an empty response body to optimize bandwidth usage, particularly important for mobile applications where PATCH operations may occur frequently during interactive forms.

System-generated values are typically updated automatically during PATCH operations.

PATCH /{namespace}/{version}/{resource}/{resource-id}
http
PATCH /astrobiology/v1/species/SPX-AQUA-001
Content-Type: application/json
If-Match: "etag-value-123"
Authorization: Bearer {token}
{
"common_name": "Giant Stellar Jellyfish",
"temperature_range": {
"max_celsius": -2
}
}
http
204 No Content
ETag: "etag-value-124"
Last-Modified: Wed, 01 Mar 2024 10:30:00 GMT
http

Note: ETag and If-Match headers help prevent concurrent modification conflicts.

PATCH operations use the same status codes as PUT operations. See the Update Individual Resource section for details.

Removes a specific resource from the collection. DELETE operations are idempotent to support retry scenarios in unreliable network conditions—always return 204 No Content regardless of whether the resource exists.

Avoid returning 404 Not Found for missing resources, as this could confuse retry logic by suggesting the resource never existed. Use GET requests to verify resource existence before deletion if needed.

DELETE /{namespace}/{version}/{resource}/{resource-id}
http
DELETE /astrobiology/v1/species/SPX-EXTINCT-999
Authorization: Bearer {token}
http
204 No Content
http
Status CodeScenario
204 No ContentResource deleted successfully (or already deleted)
404 Not FoundOnly if deletion status must be communicated
409 ConflictResource cannot be deleted due to dependencies

Creates a new resource within the collection. The request payload typically contains fewer fields than GET/PUT operations, as the server generates system values like identifiers and timestamps.

The server usually generates unique identifiers for new resources. For client-supplied identifiers, see Create New Resource - Consumer Supplied Identifier below.

Upon successful creation, the new resource becomes accessible through the collection URI with its assigned identifier.

The response includes hypermedia links (rel: self) for the new resource and related operations. Additionally, the Location header contains the URI of the newly created resource.

POST /{namespace}/{version}/{resource}
http

Server-generated fields are omitted from the request payload:

POST /astrobiology/v1/species
Content-Type: application/json
Authorization: Bearer {token}
{
"scientific_name": "Crystallinus luminous",
"common_name": "Crystal Light Organism",
"habitat": "crystalline",
"planet_origin": "Titan",
"classification": {
"kingdom": "Xenobiota",
"phylum": "Crystallophyta"
},
"bioluminescent": true
}
http
201 Created
Location: {baseurl}/astrobiology/v1/species/SPX-XENO-127
ETag: "etag-new-species-001"
{
"_links": {
"self": { "href": "{baseurl}/species/SPX-XENO-127" },
"collection": { "href": "{baseurl}/species" },
"planet": { "href": "{baseurl}/planets/TITAN" }
},
"id": "SPX-XENO-127",
"scientific_name": "Crystallinus luminous",
"common_name": "Crystal Light Organism",
"classification": {
"kingdom": "Xenobiota",
"phylum": "Crystallophyta",
"class": "Luminaria"
},
"habitat": "crystalline",
"planet_origin": "Titan",
"bioluminescent": true,
"discovery_status": "newly_catalogued",
"discovered_date": "2159-03-01T10:30:00Z",
"last_updated": "2159-03-01T10:30:00Z"
}
http
Status CodeScenario
201 CreatedResource created successfully
400 Bad RequestInvalid request data
409 ConflictResource already exists (for unique constraints)
422 Unprocessable EntityBusiness rule violations

Create New Resource - Client-Supplied Identifier

Section titled “Create New Resource - Client-Supplied Identifier”

When clients provide resource identifiers, use the PUT method since the operation becomes idempotent regardless of whether it creates or updates a resource.

PUT /{namespace}/{version}/{resource}/{client-supplied-id}
http
PUT /astrobiology/v1/species/EARTH-LEGACY-001
Content-Type: application/json
Authorization: Bearer {token}
{
"id": "EARTH-LEGACY-001",
"scientific_name": "Homo sapiens",
"common_name": "Human",
"habitat": "terrestrial",
"planet_origin": "Earth",
"classification": {
"kingdom": "Animalia",
"phylum": "Chordata",
"class": "Mammalia"
},
"intelligence_level": "sentient"
}
http

New Resource Created:

201 Created
Location: {baseurl}/astrobiology/v1/species/EARTH-LEGACY-001
ETag: "etag-legacy-001"
{
"_links": {
"self": { "href": "{baseurl}/species/EARTH-LEGACY-001" },
"planet": { "href": "{baseurl}/planets/EARTH" }
},
"id": "EARTH-LEGACY-001",
"scientific_name": "Homo sapiens",
"common_name": "Human",
"habitat": "terrestrial",
"planet_origin": "Earth",
"intelligence_level": "sentient",
"discovered_date": "2159-03-01T10:30:00Z"
}
http

Existing Resource Updated:

204 No Content
ETag: "etag-legacy-002"
http

Collection resources provide a standardized approach to managing groups of related entities. Key principles include:

  • Consistent naming: Use plural nouns for collection URIs
  • Standard HTTP methods: Support GET, POST, PUT, PATCH, DELETE appropriately
  • Proper status codes: Return meaningful HTTP status codes
  • Hypermedia links: Include HATEOAS links for discoverability
  • Pagination: Handle large datasets efficiently
  • Error handling: Provide clear, actionable error messages