nushell icon indicating copy to clipboard operation
nushell copied to clipboard

Allow `http post` to have an integer as post body

Open Turtyo opened this issue 1 year ago • 0 comments

Related problem

http post does not accept an integer (and probably doesn't accept any kind of numerical data for that matter, I only tested for int) as its post body.

I was using an axum server to deserialize JSON input via a POST request, and it turns out cURL can send integer just fine, but Nu's http post can't. Below the two commands I used: cURL:

curl -X POST "http://127.0.0.1:3000/i-like-int" -H "Content-Type: Application/Json" -d '42'

All data is between '' with cURL, so i'm really giving it an int (a string would be '"42"' with double quotes inside the single quotes). This cURL call works and produces the expected result. Nu

http post --allow-errors --full -t application/json "http://127.0.0.1:3000/i-like-int" 42

I get:

Error: nu::shell::io_error

  × I/O error
  help: unsupported body input

Trying with other variations fails also:

http post --allow-errors --full -t application/json "http://127.0.0.1:3000/i-like-int" "42"
http post --allow-errors --full -t application/json "http://127.0.0.1:3000/i-like-int" '42'

But this time it's because axum on the other side gets a string and can't deserialize:

Failed to deserialize the JSON body into the target type: invalid type: string "42", expected u64 at line 1 column 4

See below for the code using axum.

Describe the solution you'd like

Allow http post to get an int (or any numerical accepted by the JSON standard / a POST data) as an input type. I'm not sure about the actual technical solution, I tried glancing at the part of the code responsible for handling the inputs of http post but I got a bit lost.

Describe alternatives you've considered

No response

Additional context and details

The code I used to test this is available here: https://github.com/Turtyo/nu_http_post_int_test

I'm using Nu 0.97.1

Turtyo avatar Aug 23 '24 19:08 Turtyo