Skip to main content

Collection Types

Collections group multiple objects together.

Type Hierarchy

┌─────────────────────────────────────────┐
│ Collection │
├───────────────────┬─────────────────────┤
│ OrderedCollection │ CollectionPage │
│ │ OrderedCollectionPage│
└───────────────────┴─────────────────────┘

Collection

Unordered set of items.

{
"@context": "https://www.w3.org/ns/activitystreams",
"type": "Collection",
"id": "https://example.com/collection",
"totalItems": 3,
"items": [
"https://example.com/item/1",
"https://example.com/item/2",
"https://example.com/item/3"
]
}

OrderedCollection

Items in specific order (newest first typically).

{
"@context": "https://www.w3.org/ns/activitystreams",
"type": "OrderedCollection",
"id": "https://example.com/users/alice/outbox",
"totalItems": 150,
"first": "https://example.com/users/alice/outbox?page=true",
"last": "https://example.com/users/alice/outbox?page=true&min_id=0"
}

CollectionPage

A page within a collection.

{
"@context": "https://www.w3.org/ns/activitystreams",
"type": "CollectionPage",
"partOf": "https://example.com/collection",
"items": ["..."],
"next": "https://example.com/collection?page=2"
}

OrderedCollectionPage

A page with ordered items.

{
"@context": "https://www.w3.org/ns/activitystreams",
"type": "OrderedCollectionPage",
"id": "https://example.com/users/alice/outbox?page=true",
"partOf": "https://example.com/users/alice/outbox",
"orderedItems": [
{ "type": "Create", "object": { "type": "Note" } }
],
"next": "https://example.com/users/alice/outbox?page=2",
"prev": "https://example.com/users/alice/outbox?page=0"
}

Properties

PropertyTypeDescription
totalItemsIntegerTotal count
itemsArrayCollection items
orderedItemsArrayOrdered items
firstURLFirst page
lastURLLast page
currentURLCurrent page
nextURLNext page
prevURLPrevious page
partOfURLParent collection

Common Uses

CollectionTypePurpose
inboxOrderedCollectionReceived activities
outboxOrderedCollectionPublished activities
followersOrderedCollectionFollower list
followingOrderedCollectionFollowing list
likedOrderedCollectionLiked objects
sharesCollectionBoost/announce list
repliesCollectionComment thread

Pagination Pattern

┌─────────────────────────────────────────────────────┐
│ OrderedCollection (root) │
│ totalItems: 500 │
│ first: /outbox?page=true ──────┐ │
└────────────────────────────────│────────────────────┘

┌─────────────────────────────────────────────────────┐
│ OrderedCollectionPage (page 1) │
│ orderedItems: [20 items] │
│ next: /outbox?page=2 ──────────┐ │
└────────────────────────────────│────────────────────┘

┌─────────────────────────────────────────────────────┐
│ OrderedCollectionPage (page 2) │
│ orderedItems: [20 items] │
│ next: /outbox?page=3 │
└─────────────────────────────────────────────────────┘

Implementation

app.get('/users/:user/outbox', async (req, res) => {
const page = req.query.page;
const user = req.params.user;

if (!page) {
// Return collection summary
const count = await getActivityCount(user);
return res.json({
"@context": "https://www.w3.org/ns/activitystreams",
"type": "OrderedCollection",
"id": `https://example.com/users/${user}/outbox`,
"totalItems": count,
"first": `https://example.com/users/${user}/outbox?page=true`
});
}

// Return paginated items
const activities = await getActivities(user, page);
res.json({
"@context": "https://www.w3.org/ns/activitystreams",
"type": "OrderedCollectionPage",
"partOf": `https://example.com/users/${user}/outbox`,
"orderedItems": activities,
"next": `https://example.com/users/${user}/outbox?page=${page + 1}`
});
});

See Also