httpie / cli

🥧 HTTPie CLI — modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more.
https://httpie.io
BSD 3-Clause "New" or "Revised" License
33.37k stars 3.67k forks source link

Ability to post arrays of anonymous JSON objects #121

Closed chuma closed 11 years ago

chuma commented 11 years ago

Was trying to use httpie to post multiple events using the http://open.sen.se/ API. This accepts an array of unnamed objects in the form of:

[
    {
        "feed_id": 12345,
        "value": "foo"
    },
    {
        "feed_id":23456,
        "value": 2134
    },
    ...
]

Found that I could not seem to make httpie create JSON like this. Attempting to use the := separator for raw JSON without a key name created this output:

[victor@klamm ~]$ http -p B api.sen.se/events/  :='[{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}]'
{
    "": [
        {
            "feed_id": 24571, 
            "value": 64.0
        }, 
        {
            "feed_id": 24572, 
            "value": 60.0
        }
    ]
}
jkbrzt commented 11 years ago

@chuma, this you can do by passing the raw JSON in via STDIN. For example:

echo '[{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}]' | http api.sen.se/events/ 
zhao-ji commented 7 years ago

@jakubroztocil good job! you solve my problem

evandro777 commented 7 years ago

@jakubroztocil, I am using the http 0.9.2 and it seens that it doesn't work that anymore.

I've created a test.php with the code:

<?php
print_r($_REQUEST);

Then i tried the requests below:

echo '[{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}]' | http http://localhost/CRMvTiger_Rodobens/test.php Return: Array ( )

echo '[{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}]' | http --form http://localhost/CRMvTiger_Rodobens/test.php Return: Array ( )

echo '[{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}]' | http --json http://localhost/CRMvTiger_Rodobens/test.php Return: Array ( )

echo '{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}' | http http://localhost/CRMvTiger_Rodobens/test.php Return: Array ( )

echo '{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}' | http --json http://localhost/CRMvTiger_Rodobens/test.php Return: Array ( )

echo '{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}' | http --form http://localhost/CRMvTiger_Rodobens/test.php Return: Array ( [{"feed_id":24571,"value":_640},{"feedid":24572,"value":60_0} ] => )

The only which return something is the last one, but not was i was expecting, it returned all json as a key with an empty value.