Skip to content
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

Documentation example showing how to post raw JSON to some route #882

Open
nhooey opened this issue Mar 6, 2020 · 1 comment
Open

Documentation example showing how to post raw JSON to some route #882

nhooey opened this issue Mar 6, 2020 · 1 comment
Labels

Comments

@nhooey
Copy link

@nhooey nhooey commented Mar 6, 2020

It's not clear from the website's documentation, or the --help output, how to do the following equivalent curl task:

Post a raw JSON query to ElasticSearch:

curl \
    --header "Content-Type: application/json" \
    --request POST \
    --data '{ "_source": [ "restricted_countries.*" ], "query": { "match_all": {} }, "size": 1000 }' \
    'http://localhost:9200/_search'

The examples seem to show how to post form values and other stuff.

It would be great if there was a way to do this, and if it was documented in all places, such that searching for "httpie post json" would show the answer in the search result context of Google's top hits.

After a quick read of the documentation, I'm not even sure if it's possible, but I didn't dig that deep.

@jakubroztocil
Copy link
Owner

@jakubroztocil jakubroztocil commented Mar 8, 2020

You are right, this should be made more clear in the docs.

This is how you would make the same request with httpie:

$ echo '{ "_source": [ "restricted_countries.*" ], "query": { "match_all": {} }, "size": 1000 }'  \
| http :9200/_search

I.e., pass the raw request data through stdin. It’s explained here https://httpie.org/doc#redirected-input

(You don’t need to explicitly specify that you want POST, JSON content-type, nor localhost — those are the defaults.)

Repository owner deleted a comment May 2, 2020
Repository owner deleted a comment from naeim249 May 10, 2020
@jakubroztocil jakubroztocil added the docs label May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
@nhooey @jakubroztocil and others
You can’t perform that action at this time.