# Request collections

A collection keeps requests you send again and again: a login, the API
calls of one feature, a sequence you replay after each deploy. Open
**Collections** from the Proxy tools.

## Definitions, not sends

An item in a collection is a definition: the raw request, where it goes
(scheme, host, port), how it is sent (follow redirects, timeout,
Content-Length) and a note. Nothing is ever sent from a collection.
Opening a definition (Enter, a double click, or **Open in Repeater** in
its menu) creates a new Repeater tab, and the request is sent from
there under the vault's scope, its engagement rules and the emergency
stop.

To add a definition, open or edit a Repeater tab, then choose
**Save Repeater tab here** in the open collection.

## Organising

- Create a collection by naming it at the top of the list.
- Right-click a collection (or press the menu key) to rename, export or
  delete it; deleting asks in the row first.
- Right-click a request to open, rename, move up or down, copy its raw
  text or remove it. Delete on a focused row asks to remove it.

A vault holds at most 200 collections, and a collection at most 500
requests.

## Export and import

**Export JSON** writes a `phantom.collection/1` file: the collection's
name, description and its definitions, without ids. **Import JSON…**
always creates a new collection from such a file; it never changes an
existing one. Raw requests are exported as stored, so a collection
holding session cookies exports them too: check before sharing a file.

## Agents

Agents with `http_evidence.read` list collections and read them with
credentials masked (`collection_list`, `collection_get`); with
`http_evidence.update` they create collections and add definitions
(`collection_create`, `collection_add`), recorded with actor "agent".
Masked text is refused, so a definition never stores `••••` in place of
a credential. Renaming, reordering, deleting, export and import stay
with the user.

## REST

| Route | Does |
|---|---|
| `GET /api/v1/vaults/{id}/collections` | Collections by name, with request counts |
| `POST /api/v1/vaults/{id}/collections` | Create (`name`, `description`) |
| `GET /api/v1/vaults/{id}/collections/{cid}` | A collection with its requests in order |
| `PATCH`, `DELETE /api/v1/vaults/{id}/collections/{cid}` | Rename or describe; delete with its requests |
| `GET /api/v1/vaults/{id}/collections/{cid}/export` | The `phantom.collection/1` export |
| `POST /api/v1/vaults/{id}/collections/import` | Create a collection from an export |
| `POST /api/v1/vaults/{id}/collections/{cid}/items` | Add a definition at the end |
| `PATCH`, `DELETE /api/v1/vaults/{id}/collections/{cid}/items/{iid}` | Change or move (`position`); remove |
