Skip to content

fix: pass the body as string regardless of it is json #120

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
wants to merge 1 commit into from

Conversation

teto
Copy link
Collaborator

@teto teto commented Jun 23, 2022

fix: pass the body as string regardless of it is json else we hit errors in plenary.

In Plenary we can set the "body" as a string (either filename or the actual content of the payload)
or as a table in which case it is passed as curl --data . According to the doc, the latter does:

        -d, --data <data>
                  (HTTP MQTT) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare
                  to -F, --form.

Currently rest.nvim sends a table when the file is a json one which makes no sense as per curl doc so always send it as a string (aka as "content")

The relevant plenary code;
https://github.com/nvim-lua/plenary.nvim/blob/1da13add868968802157a0234136d5b1fbc34dfe/lua/plenary/curl.lua#L183-L197

@teto
Copy link
Collaborator Author

teto commented Jun 23, 2022

btw looking at https://www.reddit.com/r/neovim/comments/ug9ypl/restnvim_is_looking_for_maintainerscontributors/ , I dont really want to get involved with the development but I wouldn't mind merging rights to be able to merge the occasionnal fixes.

@teto
Copy link
Collaborator Author

teto commented Jun 23, 2022

It's possible to see the issue using the following json file

{
    "_categoricalParams": [
        {
            "allLevels": [
                "one",
                "three",
                "two"
            ],
            "currentLevel": "one",
            "description": "",
            "name": "cat_param1",
            "reference": ""
        },
        {
            "allLevels": [
                "one",
                "three",
                "two"
            ],
            "currentLevel": "one",
            "description": "",
            "name": "cat_param2",
            "reference": ""
        },
        {
            "allLevels": [
                "one",
                "three",
                "two"
            ],
            "currentLevel": "one",
            "description": "",
            "name": "cat_param3",
            "reference": ""
        }
    ]
	}

Without this PR, I get:

[rest.nvim] Failed to perform the request.                                                                                                                                                                                                                                                                                      
Make sure that you have entered the proper URL and the server is running.                                                                                                                                                                                                                                                       
Traceback: /home/teto/neovim/plenary.nvim/lua/plenary/curl.lua:57: attempt to concatenate a table value  

else we hit errors in plenary.
Plenary supports a body set as a string (either filename or the content)
and a table in which case it is passed as `curl --data` which according to the doc:

    -d, --data <data>
              (HTTP MQTT) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare
              to -F, --form.

We send a table when the file is a json one which makes no sense as per
curl doc so always send it as a string (aka as "content")

The relevant plenary code;
https://github.com/nvim-lua/plenary.nvim/blob/1da13add868968802157a0234136d5b1fbc34dfe/lua/plenary/curl.lua#L183-L197
@teto
Copy link
Collaborator Author

teto commented Aug 29, 2022

apparently fixed by #125 (haven't tested)

@teto teto closed this Aug 29, 2022
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 this pull request may close these issues.

1 participant