Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for sendRequest functionality #3845

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

pooja-bruno
Copy link
Collaborator

@pooja-bruno pooja-bruno commented Jan 20, 2025

Description

This PR introduces support for the sendRequest function, enhancing the framework's ability to handle HTTP requests dynamically. The implementation supports multiple HTTP methods (GET, POST, PUT, PATCH, DELETE) and allows Callback-based execution.

Key Changes:

  • Added sendRequest function with support for:
    • Callback-style request handling for asynchronous operations.
  • Enhanced error handling to gracefully manage HTTP response errors and exceptions.

Contribution Checklist:

  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

@@ -153,6 +155,63 @@ class Bru {
sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

sendRequest(requestConfig, callback) {
Copy link

@thiagomini thiagomini Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to send the request and pass a specific variable to be used in either the pre or post scripts?

For instance, I'd like to call bru.sendRequest('./items/delete-item', { itemId: myCustomItemId }). This would allow developers to customize further their scripts by replacing "request-scoped" variables

Copy link
Contributor

@helloanoop helloanoop Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thiagomini Bruno provides an API, bruno.runRequest('items/delete-item'), to trigger another request already defined in Bruno.

The sendRequest() API, on the other hand, is used for making direct HTTP requests.

It seems logical to support passing variables when using sendRequest(). Could you please create a new GitHub issue outlining this requirement?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see @helloanoop , thanks for the info! So, my idea is actually related to passing variables using the bruno.runRequest, do we have that? If not, I'll create an issue asking for that feature

@pull-request-size pull-request-size bot added size/L and removed size/M labels Jan 21, 2025
@naman-bruno
Copy link
Contributor

Looks great! Just curious, shouldn't the proxy be applied to the sendRequest as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants