Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Request body from stdin #42

Merged
merged 2 commits into from
Dec 8, 2021
Merged

Request body from stdin #42

merged 2 commits into from
Dec 8, 2021

Conversation

gbmor
Copy link
Contributor

@gbmor gbmor commented Dec 5, 2021

I thought this would be a handy addition. It will also make requests with a body more easily scriptable.

  • Checks if data is being passed via stdin, and if so, uses it as the request body (and ignores -b / --body). This does not try to guess the content-type, it only replaces the -b flag.
  • If data is not being passed via stdin, use whatever is being passed via -b (or nothing if the flag is omitted).

Example with redirection:

$ cat myrequest.json
{
  "foo": "bar"
}

$ hopp-cli post -c js http://example.com <myrequest.json

Example with pipes:

$ echo '{"foo":"bar"}' | hopp-cli post -c js http://example.com

If you combine stdin and -b, then -b is ignored:

$ echo '{"foo":"bar"}' | hopp-cli post -c js -b '{"other":"data"}' http://example.com

Request body: {"foo":"bar"}

But you can still use -b by itself:

$ hopp-cli post -c js -b '{"other":"data"}' http://example.com

Request body: {"other":"data"}

Copy link
Contributor

@athul athul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, Looks Good to Me 🙌🙌. Thanks @gbmor 🙌🙌

@athul
Copy link
Contributor

athul commented Dec 5, 2021

Also, would be great if you could add about the same to the Readme

@gbmor
Copy link
Contributor Author

gbmor commented Dec 5, 2021

@athul no problem, I've just added a README change to the PR.

@athul
Copy link
Contributor

athul commented Dec 8, 2021

@liyasthomas merging this

@athul athul merged commit 84d9335 into hoppscotch:master Dec 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants