bruno icon indicating copy to clipboard operation
bruno copied to clipboard

Save Response Examples

Open akshat-khosya opened this issue 1 year ago • 11 comments

This feature was mentioned in Bruno Road map. I would like to work on it.

akshat-khosya avatar Dec 18 '23 14:12 akshat-khosya

While doing this features. One question arises where should I store examples of a particular request, there are following option:

  1. .bru file of each request (examples array)
  2. Create A JSON for a collection storing with seq number so that they can be mapped.
  3. Create a seprate json for each request. @helloanoop @Its-treason Can you help to suggest which way should I do it or any other suggestion.

akshat-khosya avatar Dec 19 '23 12:12 akshat-khosya

The response examples for each request will be stored inside the .bru file itself

This should be possibly once the Bru Lang is live. Here is how it would look like

http: {
  method: 'GET'
  url: 'https://www.usebruno.com/login'
  headers: {
    Accept: 'application/json'
  }
  body: {
    type: json
    data: '''
      {
        "username": "bruno",
        "password": "secret",
      }
    '''
  }

  @status(200)
  @description('Login successful')
  response: {
    headers: {
      Content-Type: 'application/json'
    }
    data: '''
      {
        "status": true
      }
    '''
  }

  @status(401)
  @description('Login failed')
  response: {
    headers: {
      Content-Type: 'application/json'
    }
    data: '''
      {
        "status": false
      }
    '''
  }
}

helloanoop avatar Jan 25 '24 15:01 helloanoop

okay, I will be working on this feature when Bru Lang is live.

akshat-khosya avatar Jan 29 '24 10:01 akshat-khosya

I think it should like this we need to have Id for each example and we need to also store request data sent at that time, later on it might change in future.

http: {
  method: 'GET'
  url: 'https://www.usebruno.com/login'
  headers: {
    Accept: 'application/json'
  }
  body: {
    type: json
    data: '''
      {
        "username": "bruno",
        "password": "secret",
      }
    '''
  }

  @id(1)
  @status(200)
  @description('Login successful')
  response: {
    headers: {
      Content-Type: 'application/json'
    }
    data: '''
      {
        "status": true
      }
    '''
  }
request: {
    headers: {
      Content-Type: 'application/json'
    }
    body: '''
      {
        "status": true
      }
    '''
... method, url,parama
  }


  @id(2)
  @status(401)
  @description('Login failed')
  response: {
    headers: {
      Content-Type: 'application/json'
    }
    data: '''
      {
        "status": false
      }
    '''
  }
}
request: {
    headers: {
      Content-Type: 'application/json'
    }
    body: '''
      {
        "status": true
      }
    '''
... method, url,parama
  }

akshat-khosya avatar Feb 04 '24 12:02 akshat-khosya

Hi, will this feature might be released anytime soon? We're exploring postman alternatives at the moment and the feature to save examples is one of our top priorities.

devesh-anand avatar Mar 08 '24 07:03 devesh-anand

+1. Response examples are a hygiene feature

vibin avatar Mar 17 '24 10:03 vibin

Also, piggy backing off of this idea (using Docs tab for response examples), it would be great to allow including content from other files using markdown-it-include.

What the .bru would look like:

docs {
  Response examples:
  
  !!!include(example1.md)!!!

  !!!include(example2.md)!!!
}

This looks like a great workaround to have till we get the response examples feature

vibin avatar Mar 17 '24 10:03 vibin

+1 for this feature. Saving response is handy, as you can't always hit API, especially for POST & PUT. Makes thing easy to debug.

shivamkj avatar Apr 10 '24 07:04 shivamkj

@helloanoop Why does it need to have a different response for each status code stored? Shouldn't a call be reproducable, so that it should have only one possible response? I also think it would make more sense to simply redirect the output to a file with the same name in the same directory, that simply has a different extension.

test.bru could store the response in test.out or whatever. (to be discussed, out probably has high collision potential)

This could be an opt-in feature, out files could be excluded from version control, for those who wish to inspect the output in a different editor, but not have it be part of the repo. On top of that it could work well for the issue linked by @tsriram if output could also be suppressed in Bruno itself.

martin-braun avatar Apr 25 '24 03:04 martin-braun

@helloanoop @akshat-khosya, I'd like to pick this up if no one is already working on it.

techiespace avatar Aug 06 '24 11:08 techiespace

This is a fairly complex feature considering that the bru lang would need updates. We are considering to move to yaml as a standard to makes things easier.

This will take more time. We will revisit this and setout an approach once we release initial support for yaml storage in Bruno

helloanoop avatar Aug 08 '24 11:08 helloanoop