federicotdn / verb

Organize and send HTTP requests from Emacs
https://melpa.org/#/verb
GNU General Public License v3.0
545 stars 20 forks source link

verb-send-request-on-point doesn't correctly work for source blocks #53

Closed agzam closed 5 months ago

agzam commented 1 year ago

verb-send-request-on-point works for both - tree-structured and source-block approaches. But it doesn't seem to correctly detect the source block at point, when there are multiple within the same heading, i.e.,

* Testing requests :verb:
 template https://api.thecatapi.com/v1

** subheading
    #+begin_src verb :wrap src json :op send get-body
    GET /breeds
    #+end_src

    #+begin_src verb :wrap src json :op send get-body
    GET /sources
    #+end_src

when the cursor is at the second source code, running verb-send-request-on-point should work for the second one, currently, it sends the request for the first source block. That basically makes problematic to keep multiple source blocks within the same heading.


verb-export-request-on-point-curl, as it looks like, also has the same issue, it doesn't correctly detect the source block at point.

federicotdn commented 1 year ago

Thanks for reporting this. The idea was to always keep one request spec per Org heading - currently all of Verb works like this. In your case, you could add two level-3 headings for each request spec. Would that work with your workflow, or does it break something else?

agzam commented 1 year ago

I think you're missing the point. I understand that probably, initially, you built it with the assumption that it primarily will be used within a hierarchy of headings. However, verb-send-request-on-point incidentally (or by design) also works with source blocks.

And that may mislead people to think that it works for any source block, after all the command is called -on-point, not -on-point-within-a-heading. That is exactly what happened to me. I spent some time scratching my head, wondering why data for two different endpoints looks the same.

I think it would be wise to make it either fail with a message or make it do the right thing. This is exactly what I'm trying to do in https://github.com/federicotdn/verb/pull/55

Of course, I'm not arguing for the correctness of that approach (you may suggest doing it differently), but fundamentally, I think, it is a problem worth fixing.

federicotdn commented 5 months ago

Finally fixed this! You were right; additionally, I had already more or less planned for this scenario (sending requests embedded in Babel blocks using verb-send-request-on-point), only that my solution was to simply take the first block. See: https://github.com/federicotdn/verb/commit/b878d52ebc8214b2aedd59165aa89f8d918ed95c