Skip to content

Sending JSON-payload #114

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

Closed
diskriminantti opened this issue May 14, 2022 · 9 comments · Fixed by #125
Closed

Sending JSON-payload #114

diskriminantti opened this issue May 14, 2022 · 9 comments · Fixed by #125

Comments

@diskriminantti
Copy link

Hello! I just installed this plugin, and it works pretty well so far! I'm having some issues though, not sure if I'm understanding this plugin correctly. I'm trying to send some data as json, like this:

POST http://httpbin.org/post
Content-Type: application/json

{ "name": "Test"}

I get a response like this in the response window:

POST http://httpbin.org/post
Content-Type: application/json

{
  "args": {},
  "data": "name=Test",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "deflate, gzip, br",
    "Content-Length": "9",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "User-Agent": "curl/7.68.0",
  },
  "json": null,
  "origin": "XXX.XXX.XXX.XXX",
  "url": "http://httpbin.org/post"
}

I was expecting to get the same data back in the json -field of the response, but it's null as you can see. I checked the output of RestNvimPreview and it gave me this: curl -sSL --compressed -X 'POST' -H 'Content-Type: application/json' -d 'name=Test' 'http://httpbin.org/post' . Trying to send that from the command line gives me the same response as before.

I kinda figured with the Content-Type header, the data would be sent as json, but it seems like that's not the case. Is this intended behavior, or have I misunderstood something? It's a great plugin nonetheless, thanks for creating it!

@jceb
Copy link

jceb commented May 16, 2022

Same here. The issue comes from plenary. It doesn't seem to support JSON. Instead, it generates = separated entries that are sent over the wire. See https://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/curl.lua#L108

The issue was caused by commit 33c6829 / issue #102. Instead of a string, a table is returned which triggers plenary's behavior.

@diskriminantti
Copy link
Author

Thanks for the heads up! At least for now, I reverted back to commit e5f68db73276c4d4d255f75a77bbe6eff7a476ef which works as expected.

@jackpinto
Copy link

jackpinto commented May 16, 2022

Same here! Is there any workaround for it? Beside downgrade rest.nvim?

@kennycallado
Copy link

Same here!

@srihari93
Copy link
Contributor

@NTBBloodbath Please revert merging my latest PR, It is the root cause for the issue.

@nagy135
Copy link

nagy135 commented May 25, 2022

any progress on this ? I remember reading that maintainer is done with this repo (on reddit) and this would correlate with 12 old last commit. Any forks if so ?

@dung-june
Copy link

any progress on this ? I remember reading that maintainer is done with this repo (on reddit) and this would correlate with 12 old last commit. Any forks if so ?

You can consider this fork to resolve this issue: https://github.com/teto/rest.nvim/tree/always-send-string
It works for me :)

@Emptyfruit
Copy link

I just installed the plugin for the first time and have this bug.
Neovim 0.8.1

@rochacbruno
Copy link
Contributor

Headers on POST must be lower case

- Content-Type: application/json
+ content-type: application/json

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

Successfully merging a pull request may close this issue.

9 participants