rest-nvim / rest.nvim

A fast Neovim http client written in Lua
GNU General Public License v3.0
1.61k stars 142 forks source link

Support for HTML request bodies #386

Closed bennypowers closed 2 months ago

bennypowers commented 6 months ago

Using release 2.0.1, I got:

POST http://localhost:3333
Content-Type: text/html
Accept: text/html

<rh-card>
  <h2 slot="header">SSR</h2>
</rh-card>
   Error  09:09:57 AM notify.error [rest.nvim] ERROR: The tree-sitter node at the range [0:0 - 5:28] has a syntax error and cannot be parsed
   Error  09:09:57 AM msg_show.lua_error   Rest run Error executing Lua callback: .../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:143: attempt to index local 'document_node' (a nil value)
stack traceback:
    .../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:143: in function 'traverse_variables'
    .../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:434: in function 'parse'
    ...al/share/nvim/lazy/rest.nvim/lua/rest-nvim/functions.lua:61: in function 'exec'
    ...cal/share/nvim/lazy/rest.nvim/lua/rest-nvim/commands.lua:44: in function 'impl'
    ...cal/share/nvim/lazy/rest.nvim/lua/rest-nvim/commands.lua:182: in function <...cal/share/nvim/lazy/rest.nvim/lua/rest-nvim/commands.lua:165>

More generally, rest.nvim may parse the mimetype in the Content-Type header and parse the request body using the associated ts parser

Originally posted by @bennypowers in https://github.com/rest-nvim/rest.nvim/issues/242#issuecomment-2119116753

boltlessengineer commented 2 months ago

Closing due to tree-sitter-http v3 release. This is now possible in rest.nvim v3

bennypowers commented 2 months ago

Thanks. I added this query in ~/.config/nvim/after/queries/http/injections.scm to get HTML highlighting, since i suppose i don't have the xml highlighter installed

; extends

(document
  (section
    (request
      (header
        (header_entity) @_header
        (value) @_value)
      (#eq? @_value "text/html")
      (#match? @_header "^[cC][oO][nN][tT][eE][nN][tT]-[tT][yY][pP][eE]$")
      (xml_body) @injection.content
      (#set! injection.language "html"))))