Skip to content

Commit

Permalink
add: sendRequest in hintWords and created bru file for each method
Browse files Browse the repository at this point in the history
  • Loading branch information
pooja-bruno committed Jan 22, 2025
1 parent e4f3f05 commit 46bd9af
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/bruno-app/src/components/CodeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ if (!SERVER_RENDERED) {
'bru.setNextRequest(requestName)',
'req.disableParsingResponseJson()',
'bru.getRequestVar(key)',
'bru.sendRequest(requestConfig, callback)',
'bru.sleep(ms)',
'bru.getGlobalEnvVar(key)',
'bru.setGlobalEnvVar(key, value)',
'bru.runner',
'bru.runner.setNextRequest(requestName)',
'bru.runner.skipRequest()',
'bru.runner.stopExecution()'
'bru.runner.stopExecution()',
];
CodeMirror.registerHelper('hint', 'brunoJS', (editor, options) => {
const cursor = editor.getCursor();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

meta {
name: deleteRequest
type: http
seq: 8
}

get {
url: {{host}}/ping
body: none
auth: none
}

tests {
test("should delete post", function() {
const deleteRequest = await bru.sendRequest({
url: 'https://jsonplaceholder.typicode.com/posts/1',
method: 'DELETE'
});
console.log('DELETE Status:', deleteRequest.code);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
meta {
name: getRequest
type: http
seq: 8
}

get {
url: {{host}}/ping
body: none
auth: none
}

tests {
test("should get data", function() {
const getRequest = await bru.sendRequest(
{
url: 'https://jsonplaceholder.typicode.com/posts/1',
method: 'GET',
},
(error, response) => {
if (error) {
console.error('GET Request failed:', error);
return;
}
console.log('GET Response via callback:', response.body);
}
);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
meta {
name: patchRequest
type: http
seq: 8
}

get {
url: {{host}}/ping
body: none
auth: none
}

tests {
test("should patch existing post", function() {
const patchRequest = await bru.sendRequest({
url: 'https://jsonplaceholder.typicode.com/posts/1',
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
data: {
title: 'Only Update Title'
}
});
console.log('PATCH Response:', patchRequest.body);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
meta {
name: postRequest
type: http
seq: 8
}

get {
url: {{host}}/ping
body: none
auth: none
}

tests {
test("should create new post", function() {
const createPost = await bru.sendRequest({
url: 'https://jsonplaceholder.typicode.com/posts',
method: 'POST',
data: {
title: 'New Post',
body: 'New Content',
userId: 1
}
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
meta {
name: putRequest
type: http
seq: 8
}

get {
url: {{host}}/ping
body: none
auth: none
}

tests {
test("should update entire post with PUT request", function() {
const putRequest = await bru.sendRequest({
url: 'https://jsonplaceholder.typicode.com/posts/1',
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: {
id: 1,
title: 'Updated Title',
userId: 1
}
},);
console.log('PUT Response:', putRequest.body);
});
}

0 comments on commit 46bd9af

Please sign in to comment.