Sometimes API responses contain a lot of data.
Given an endpoint that returns JSON or XML, it would be cool to be able to do something like
http http://myapi.endpoint/ -q "abc/xyz"
and only get to see the "abc/xyz" sub-tree of the response.
+1, this would be awesome
There are some external tools for this:
聽 - jq for JSON http://stedolan.github.io/jq/
聽 - xmlstarlet and others for XML http://stackoverflow.com/a/15461774
Why not simply use them?
@corpix Thanks for the links; wasn't aware of them.
There are pros and cons to an integrated tool. I am on the fence about this; I will leave it to the developers to close this issue if they wish.
I'm afraid this is slightly beyond the scope of what httpie should support. jq
for JSON is excellent and integrates well with HTTPie via pipes. I'm planing on adding some examples to the docs, but here is a simple one for now:
$ http httpbin.org/get
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 398
Content-Type: application/json
Date: Wed, 07 Jan 2015 19:03:04 GMT
Server: gunicorn/18.0
Via: 1.1 vegur
{
"args": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connect-Time": "1",
"Connection": "close",
"Host": "httpbin.org",
"Total-Route-Time": "1",
"User-Agent": "HTTPie/0.8.0",
"Via": "1.1 vegur",
"X-Request-Id": "2b2e03a0-0449-40f1-9027-73bfe9edf31f"
},
"url": "http://httpbin.org/get"
}
$ http httpbin.org/get | jq '.headers["User-Agent"]'
"HTTPie/0.8.0"
And other tools exist for querying different formats.
Here's another example of using jq; this one happens to also use httpie-unixsocket to communicate with Docker over /var/run/docker.sock
:
$ http http+unix://%2Fvar%2Frun%2Fdocker.sock/info | jq .RegistryConfig
{
"InsecureRegistryCIDRs": [
"127.0.0.0/8"
],
"IndexConfigs": {
"docker.io": {
"Name": "docker.io",
"Mirrors": null,
"Secure": true,
"Official": true
}
},
"Mirrors": null
}
Most helpful comment
I'm afraid this is slightly beyond the scope of what httpie should support.
jq
for JSON is excellent and integrates well with HTTPie via pipes. I'm planing on adding some examples to the docs, but here is a simple one for now:And other tools exist for querying different formats.