YAML Samples
Here are sample YAML files showing common API request patterns.
GET Request
info:
name: Get User
type: http
seq: 1
http:
method: GET
url: https://api.github.com/users/usebruno
settings:
encodeUrl: trueGET with Headers
info:
name: Get with Headers
type: http
seq: 2
http:
method: GET
url: https://api.example.com/data
headers:
- name: Content-Type
value: application/json
- name: Authorization
value: Bearer topsecret
settings:
encodeUrl: trueGET with Query Parameters
info:
name: Search Users
type: http
seq: 3
http:
method: GET
url: https://api.example.com/users?filter=active&limit=10&page=1
params:
- name: filter
value: active
type: query
- name: limit
value: "10"
type: query
- name: page
value: "1"
type: query
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5GET with Path Parameters
info:
name: Get User by ID
type: http
seq: 4
http:
method: GET
url: https://api.example.com/users/:id
params:
- name: id
value: ""
type: path
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5POST with JSON Body
info:
name: Create User
type: http
seq: 5
http:
method: POST
url: https://api.example.com/users
body:
type: json
data: |-
{
"name": "John Doe",
"email": "john@example.com"
}
settings:
encodeUrl: truePOST with Form Data
info:
name: Upload Form
type: http
seq: 6
http:
method: POST
url: https://api.example.com/submit
body:
type: form-urlencoded
data:
- name: username
value: johndoe
- name: password
value: secret123
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5Request with Authentication
info:
name: Authenticated Request
type: http
seq: 7
http:
method: GET
url: https://api.example.com/protected
auth:
type: basic
username: admin
password: secret
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5Request with Pre-Request Script
info:
name: Request with Script
type: http
seq: 8
http:
method: POST
url: https://api.example.com/data
runtime:
scripts:
- type: before-request
code: |-
// Set dynamic timestamp
const timestamp = Date.now();
bru.setVar("timestamp", timestamp);
settings:
encodeUrl: trueRequest with Post-Response Script
info:
name: Login
type: http
seq: 9
http:
method: POST
url: https://api.example.com/login
body:
type: json
data: |-
{
"username": "johnnash",
"password": "governingdynamics"
}
runtime:
scripts:
- type: after-response
code: |-
// Save token for subsequent requests
bru.setVar("token", res.body.token);
settings:
encodeUrl: trueRequest with Tests
info:
name: Login with Tests
type: http
seq: 10
http:
method: POST
url: https://api.example.com/login
body:
type: json
data: |-
{
"username": "johnnash",
"password": "governingdynamics"
}
runtime:
scripts:
- type: tests
code: |-
test("should be able to login", function() {
expect(res.status).to.equal(201);
});
test("should receive the token", function() {
expect(res.body.token).to.be.a('string');
});
settings:
encodeUrl: trueRequest with Assertions
info:
name: Request with Assertions
type: http
seq: 11
http:
method: POST
url: https://api.example.com/users
runtime:
assertions:
- expression: res.status
operator: eq
value: "201"
- expression: res.body.name
operator: isString
settings:
encodeUrl: trueLast updated on