talis-fb / TReq

A CLI tool for effortless HTTP requests
GNU General Public License v3.0
50 stars 3 forks source link

Add Redirect Input to receive raw payload request body #33

Open talis-fb opened 6 months ago

talis-fb commented 6 months ago

The objective is to replicate this feature in HTTPie: https://httpie.io/docs/cli/redirected-input

Accept user for passing request data is through redirected stdin (standard input)—piping. Receiving the inputs from this method is similar to using --raw flag with the content passed in stdin.

treq PUT api.com/put < files/data.json
echo -n '{"name": "John"}' | http PATCH api.com/patch Auth:None

These three command are equivalent (consider the file.json with content as {"name": "Thales"})

treq POST api.com/post --raw '{"name": "Thales"}'
echo '{"name": "Thales"}' | treq POST api.com/post
treq POST api.com/post < file.json
cat file.json | treq POST api.com/post

Additional Considerations:

It's really important use the same abstraction used by --raw flag. That way is even possible to merge the input from this with request items.

This command

echo '{ "name": "John", "age": 21 }' | treq POST api.com/post job=dev role=admin

would request with body...

{ 
  "name": "John",
  "age": 21,
  "job": "dev",
  "role": "admin"
}