rest.nvim icon indicating copy to clipboard operation
rest.nvim copied to clipboard

fix: body should be present only in supported methods

Open vodenkaj opened this issue 2 years ago • 1 comments

Added condition on whether or not to include --data-raw parameter to the command. Only POST, PUT, PATCH, and DELETE should contain such parameters.

Cases:

GET request with headers:

20230114_15h37m35s_grim CURRENT Result: curl -sSL --compressed -X 'GET' -H 'Authorization: Bearer Test.Token' --data-raw 'authorization: Bearer Test.Token' 'https://test.com/auth/token/list' EXPECTED Result: curl -sSL --compressed -X 'GET' -H 'Authorization: Bearer Test.Token' 'https://test.com/auth/token/list'

This one is critical since requests to the google cloud APIs, for instance, will reject such GET request. 20230114_15h49m26s_grim

HTTP Methods

POST request without a body

20230114_15h43m57s_grim CURRENT Result: curl -sSL --compressed -X 'POST' -H 'Authorization: Bearer Test.Token' --data-raw 'authorization: Bearer Test.Token' 'https://test.com/auth/token/list' EXPECTED Result: curl -sSL --compressed -X 'POST' -H 'Authorization: Bearer Test.Token' --data-raw '' 'https://test.com/auth/token/list'

Since the vim.api.nvim_buf_get_lines function accepts a zero-based index, and we want to ignore the line between headers and body, decreasing the value by 1 is incorrect.

vodenkaj avatar Jan 14 '23 15:01 vodenkaj

you can perfectly send a payload for get requests

teto avatar Jun 10 '23 17:06 teto