xiaohongshu
xiaohongshu
bruno-endpoint-creation
Create professional 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"...
Full skill instructions
As a REST API expert, when creating Bruno endpoints, follow these proven patterns for professional API testing and documentation:
Development Environment (Local.bru):
vars {
baseUrl: http://localhost:3001
linkId:
apiKey: dev_api_key_change_in_production
}
Production/Staging Environments:
vars {
baseUrl: https://api.yourdomain.com
linkId:
}
vars:secret [
apiKey
]
Key Principles:
vars:secret for sensitive data in production/stagingStandard CRUD Operations Pattern:
GET /api/v1/resources # List all resources
GET /api/v1/resources/:id # Get specific resource
POST /api/v1/resources # Create new resource
PATCH /api/v1/resources/:id # Update specific resource
PUT /api/v1/resources/:id # Replace specific resource
DELETE /api/v1/resources/:id # Delete specific resource
Collection-Level Authentication (Recommended):
Set authentication once at the collection level in collection.bru:
auth {
mode: bearer
}
auth:bearer {
token: {{apiKey}}
}
Then inherit in all individual endpoints:
post {
url: {{baseUrl}}/api/v1/resources
body: json
auth: inherit
}
Individual Endpoint Authentication (When Needed):
Only use when an endpoint needs different auth than the collection:
auth:bearer {
token: {{apiKey}}
}
auth:basic {
username: {{username}}
password: {{password}}
}
headers {
X-API-Key: {{apiKey}}
}
Benefits of Collection-Level Auth:
Standard 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
}
Post-Response Scripts for Data Extraction:
Use bru.setVar() to store values in runtime variables for use across requests in the same run:
script:post-response {
// After creating a resource, store its ID in runtime variable
if (res.status === 201 && res.body && res.body.id) {
bru.setVar("resourceId", res.body.id);
bru.setVar("lastCreatedAt", res.body.created_at);
}
// After listing resources, extract the first ID for subsequent operations
if (res.status === 200 && res.body && res.body.length > 0) {
bru.setVar("resourceId", res.body[0].id);
}
}
Key Difference:
bru.setEnvVar() - Stores in environment variables (persists across requests, visible in Environment tab)bru.setVar() - Stores in runtime variables (temporary, available during current collection run)Best Practice: Use bru.setVar() for runtime variables to avoid cluttering your environment variables with ephemeral values like extracted IDs from test runs.
Pre-Request Scripts for Dynamic Data:
script:pre-request {
// Generate dynamic test data
const timestamp = Date.now();
bru.setVar("uniqueEmail", `test-${timestamp}@example.com`);
bru.setVar("randomId", Math.random().toString(36).substr(2, 9));
}
Expected Status Codes:
200 - Success (GET, PATCH, PUT)201 - Created (POST)204 - No Content (DELETE)400 - Bad Request401 - Unauthorized403 - Forbidden404 - Not Found422 - Unprocessable Entity500 - Internal Server ErrorResponse Validation Scripts:
script:post-response {
// Validate response structure
if (res.status === 200) {
if (!res.body || typeof res.body !== 'object') {
throw new Error('Expected JSON response body');
}
if (res.body.id && typeof res.body.id !== 'string') {
throw new Error('Expected string ID in response');
}
}
}
Comprehensive Endpoint Documentation:
docs {
Create a new resource in the system.
**Required Fields:**
- field1: Description of required field
- field2: Another required field description
**Optional Fields:**
- optional_field: Description of optional field
**Validation Rules:**
- field1 must be between 3-50 characters
- field2 must be a valid email format
**Response:**
- 201 Created: Returns the created resource with ID
- 422 Unprocessable Entity: Returns validation errors
- 401 Unauthorized: Invalid or missing authentication
**Example Usage:**
This endpoint is typically called after user authentication
to create new resources in the system.
}
Recommended 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
Pagination Support:
params:query {
page: 1
per_page: 20
sort: created_at
order: desc
}
Filtering & Search:
params:query {
search: "search term"
status: active
created_after: "2024-01-01"
tags: "tag1,tag2"
}
Bulk Operations:
body:json {
{
"resources": [
{"field1": "value1"},
{"field1": "value2"}
]
}
}
Test Sequence:
Environment-Specific Testing:
Never Include in Version Control:
Use Environment Variables:
Load Testing Headers:
headers {
X-Load-Test: true
X-Request-ID: {{requestId}}
}
Timing Validation:
script:post-response {
if (res.timings.duration > 5000) {
console.warn('Request took longer than 5 seconds');
}
}
This comprehensive approach ensures your Bruno collections are professional, maintainable, and follow REST API best practices while providing excellent developer experience and thorough testing coverage.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience