Here are some examples of Bru syntax. We are not recommending that below structures must be bru files. These are just examples to show how Bru can be used.
package.json
name: usebruno
private: true
workspaces: [
packages/bruno-app
packages/bruno-electron
packages/bruno-cli
]
homepage: https://usebruno.com
devDependencies: {
husky: 8.0.3
jest: 29.2.0
}
scripts: {
prepare: 'husky install'
}
overrides {
rollup: 3.2.5
}
get-users.bru
meta: {
name: Create User
type: http
seq: 1
}
http: {
method: POST
url: https://www.usebruno.com/api/v1/users
headers: {
Content-Type: application/json
}
body: {
type: json
data: '''
{
"email": "admin@usebruno.com",
"password": "password"
}
'''
}
}
pre-request-script: '''
let token = bru.getEnvVar('token'));
bru.setHeader('Authorization', 'Bearer ' + token);
'''
tests: '''
test("should create a user", () => {
expect(res.getStatus()).to.equal(200);
});
test("should return a user", () => {
const data = res.getBody();
expect(data).to.have.property('id');
expect(data).to.have.property('email');
}
'''
openapi.bru
For this example, we are also displaying the corresponding OpenAPI YAML file. This is to demonstrate how a markup lang with support for multimaps and annotations improves readability so much.
openapi: 3.0.0
info:
title: Todo API
version: 1.0.0
paths:
/todos:
get:
summary: Retrieve all Todos
responses:
'200':
description: Successful response
content:
application/json:
example:
todos:
- id: 1
title: "Complete assignment"
completed: false
- id: 2
title: "Buy groceries"
completed: true
post:
summary: Create a new Todo
requestBody:
required: true
content:
application/json:
example:
title: "New task"
completed: false
responses:
'201':
description: Todo created successfully
content:
application/json:
example:
id: 3
title: "New task"
completed: false
openapi: 3.0.0
info: {
title: Todo API
version: 1.0.0
}
paths: {
'/todos': {
@summary('Retrieve all Todos')
get: {
@description('Successful response')
@status(200)
@contentType('application/json')
response: '''
[{
"id": 1,
"title": "Complete assignment",
"completed": false
}, {
"id": 2,
"title": "Buy groceries",
"completed": true
}]
'''
@summary('Create a new Todo')
post: {
requestBody: '''
{
"title": "New task",
"completed": false
}
'''
@description('Todo created successfully')
@status(201)
@contentType('application/json')
response: '''
{
"id": 3,
"title": "New task",
"completed": false
}
'''
}
}
}