home / skills / steveclarke / dotfiles / bruno-endpoint-creation

bruno-endpoint-creation skill

/ai/skills/bruno-endpoint-creation

This skill helps you create Bruno REST API endpoints with proper environment config, authentication, and documentation for reliable testing.

npx playbooks add skill steveclarke/dotfiles --skill bruno-endpoint-creation

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.9 KB
---
name: bruno-endpoint-creation
description: Create Bruno REST API endpoint configurations with proper authentication, environment setup, and documentation. Use when setting up API testing with Bruno, creating new endpoints, or configuring collection-level authentication. Triggers on "create Bruno endpoint", "Bruno API testing", "set up Bruno collection".
---

# Bruno Endpoint Creation

Bruno-specific patterns for creating `.bru` endpoint files. Assumes familiarity with REST conventions.

## Environment Configuration

**Development (Local.bru):**
```
vars {
  baseUrl: http://localhost:3001
  linkId:
  apiKey: dev_api_key_change_in_production
}
```

**Production/Staging — use `vars:secret` for sensitive data:**
```
vars {
  baseUrl: https://api.yourdomain.com
  linkId:
}
vars:secret [
  apiKey
]
```

## Collection-Level Authentication

Set auth once in `collection.bru`, then inherit in all endpoints:

```
auth {
  mode: bearer
}

auth:bearer {
  token: {{apiKey}}
}
```

Individual endpoints inherit with `auth: inherit`:
```
post {
  url: {{baseUrl}}/api/v1/resources
  body: json
  auth: inherit
}
```

Override per-endpoint only when auth differs from the collection.

## Request Structure

```
meta {
  name: "Create Resource"
  type: http
  seq: 1
}

post {
  url: {{baseUrl}}/api/v1/resources
  body: json
  auth: inherit
}

body:json {
  {
    "resource": {
      "field1": "value1",
      "field2": "value2"
    }
  }
}

params:path {
  id: {{resourceId}}
}

params:query {
  page: 1
  limit: 20
  sort: created_at
  order: desc
}
```

## Scripting API

**Post-response — extract data for subsequent requests:**
```javascript
script:post-response {
  if (res.status === 201 && res.body && res.body.id) {
    bru.setVar("resourceId", res.body.id);
  }
}
```

**Pre-request — generate dynamic data:**
```javascript
script:pre-request {
  const timestamp = Date.now();
  bru.setVar("uniqueEmail", `test-${timestamp}@example.com`);
}
```

**Key difference:**
- `bru.setVar()` — runtime variables (temporary, current collection run only)
- `bru.setEnvVar()` — environment variables (persists, visible in Environment tab)

Use `bru.setVar()` for ephemeral values like extracted IDs from test runs.

## Documentation Block

```
docs {
  Create a new resource in the system.

  **Required Fields:**
  - field1: Description
  - field2: Description

  **Optional Fields:**
  - optional_field: Description
}
```

## Collection Folder Structure

```
Bruno Collection/
├── Environments/
│   ├── Local.bru
│   ├── Staging.bru
│   └── Production.bru
├── Authentication/
│   ├── Login.bru
│   └── Refresh Token.bru
├── Resources/
│   ├── List Resources.bru
│   ├── Get Resource.bru
│   ├── Create Resource.bru
│   ├── Update Resource.bru
│   └── Delete Resource.bru
└── Health/
    └── Health Check.bru
```

Overview

This skill creates professional Bruno REST API endpoint configurations with secure authentication, environment setup, and clear documentation. It standardizes collection-level auth, request/response handling, and reusable environment variables so Bruno collections are predictable and safe. Use it to speed up API testing, onboarding, and CI-friendly endpoint maintenance.

How this skill works

It generates Bruno-friendly files and snippets for environments, endpoints, auth blocks, request bodies, query/path params, and scripts. It recommends collection-level bearer auth, secret handling for production, pre-request dynamic data generation, and post-response extraction using bru.setVar()/bru.setEnvVar(). It also provides docs templates and test sequences to validate expected status codes and response shapes.

When to use it

  • Setting up a new Bruno collection for API testing
  • Creating or standardizing new REST endpoints (CRUD)
  • Configuring collection-level authentication and secrets
  • Preparing environment-specific configs (local, staging, production)
  • Building test sequences and response-extraction scripts

Best practices

  • Define auth at collection level (auth: inherit) to follow DRY and simplify maintenance
  • Store production secrets in vars:secret and never hardcode API keys in source files
  • Use bru.setVar() for ephemeral runtime values and bru.setEnvVar() for persistent environment changes
  • Document each endpoint with required/optional fields, validation rules, and example responses
  • Organize collections into Environments, Authentication, Resources, and Health folders for clarity

Example use cases

  • Create Local.bru with baseUrl and dev apiKey for local testing
  • Configure collection-level bearer token and inherit it across create/list/get/update/delete endpoints
  • Add pre-request script to generate unique emails and randomIds for test runs
  • Post-response script stores created resource ID to run subsequent GET/PATCH/DELETE steps
  • Prepare a production environment file with vars:secret and read-only health checks for deployment monitoring

FAQ

When should I use bru.setVar() vs bru.setEnvVar()?

Use bru.setVar() for temporary values needed only during a single run (extracted IDs). Use bru.setEnvVar() when you want values persisted across runs and visible in the Environment tab.

How do I handle different auth for a single endpoint?

Only apply individual endpoint auth when it deviates from the collection. Define auth blocks (bearer, basic, headers) inside the endpoint and avoid duplicating secrets in source; reference environment variables instead.