Code Monkey home page Code Monkey logo

Comments (23)

akvadrako avatar akvadrako commented on April 28, 2024 47

I would prefer javascript compatible syntax, so http post parent.child=value and the more complex syntax for embedded dots: [parent.with.dots]=value. The common use case should be easiest and json properties with dots are ugly to use in javascript.

from httpie.

jkbrzt avatar jkbrzt commented on April 28, 2024 38

For deeply nested JSON it's easier to use stdin. For example:

 echo '{"foo": {"bar": "baz"}}' | http url

 # Or from a file:
 http url < file.json

More examples are listed in the README.

from httpie.

sandstrom avatar sandstrom commented on April 28, 2024 13

httpie is a dream! nesting would make it even more awesome though.

It would be nice with rails-like nesting, e.g. path/to/endpoint credentials[username]=me

from httpie.

nikolay avatar nikolay commented on April 28, 2024 11

@jakubroztocil This issue has been open for 6 years! And it is such a rudimentary feature! Of course, we can all do echo, but we can use curl as well, right? The point is that httpie does all the basic REST operations. Of course, we can use it along with jarg or jo, but it's so easy to implement this within httpie, I think!

from httpie.

lastcoolnameleft avatar lastcoolnameleft commented on April 28, 2024 7

@jkbrzt For clarification are you referencing jarg for your own notes/feature development? I tried the following which didn't work:

http post localhost:3000/api foo[bar]=baz

Is received as:

body= { 'foo[bar]': 'baz' }

However, piping through jarg does seem to work:

jarg foo[bar]=baz | http post localhost:3000/api

Is received as:

body= { foo: { bar: 'baz' } }

from httpie.

merwok avatar merwok commented on April 28, 2024 5

I donโ€™t think itโ€™s that simple, or someone would have sent a pull request!

We should appreciate projects written on free time and given for free.

from httpie.

isidentical avatar isidentical commented on April 28, 2024 5

๐ŸŽ‰ This feature is now publicly available in HTTPie for Terminal 3.0:

๐Ÿ‘‰๐Ÿป https://httpie.io/docs/cli/nested-json

from httpie.

jkbrzt avatar jkbrzt commented on April 28, 2024 3

Syntax: https://www.w3.org/TR/html-json-forms/

(https://github.com/jdp/jarg)

from httpie.

akamalov avatar akamalov commented on April 28, 2024 2

Answering my own question:

http -v PUT http://10.10.10.219:8080/v2/apps/product/web/tutum-hello-world-1 instances:=2 constraints:='[["hostname", "LIKE", server1.localnet.nett"]]'

PUT /v2/apps/product/web/tutum-hello-world-1 HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Length: 85
Content-Type: application/json; charset=utf-8
Host: 10.9.158.219:8080
User-Agent: HTTPie/0.8.0

{
    "constraints": [
        [
            "hostname", 
            "LIKE", 
            "server1.localnet.net"
        ]
    ], 
    "instances": 2
}

HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Content-Length: 92
Content-Type: application/json
Expires: 0
Pragma: no-cache
Server: Jetty(8.y.z-SNAPSHOT)

{
    "deploymentId": "bde62f56-89f6-406a-9c3a-d0309ea3dde6", 
    "version": "2015-06-10T12:28:06.056Z"
}

Thanks!!

Alex

from httpie.

nikolay avatar nikolay commented on April 28, 2024 1

@merwork We appreciate it. But how many REST services you know to have only a flat JSON?

from httpie.

segevfiner avatar segevfiner commented on April 28, 2024 1

If you don't like piping JSON from jo or jarg before the http command. you can also use shell process substitution so the JSON is in a similar location when using the builtin syntax of HTTPie:

https postman-echo.com/post @<(jo hello=world)

It would still be much better if HTTPie supported a syntax like those tools of course.

from httpie.

jkbrzt avatar jkbrzt commented on April 28, 2024 1

An important consideration here is backwards compatibility. If we simply introduce a syntax relying on dots, than a script containing the following HTTPie command:

$ http httpbin.org/post  foo.bar=baz

Which currently produces this JSON:

{
    "foo.bar": "baz"
}

Would unexpectly result in:

{
    "foo": {
        "bar": "baz"
    }
}

So the command would have to be updated to escape the newly-meanignful . character:

$ http httpbin.org/post  'foo\.bar=baz'

from httpie.

mfussenegger avatar mfussenegger commented on April 28, 2024

Some sort of easier syntax for nested data would really be a nice thing to have.
There is also another issue with some syntax suggestions: #346

from httpie.

jkbrzt avatar jkbrzt commented on April 28, 2024

So nesting could be expressed either with brackets or using dot notation.

from httpie.

akamalov avatar akamalov commented on April 28, 2024

Greetings!!! Small question regarding nested json and httpie. So I have a json file:

{
      "apps": [
         { "id": "/product/web/tutum-hello-world-2",
                   "container": {
               "type": "DOCKER",
                   "docker": {
                     "image": "tutum/hello-world",
                         "network": "BRIDGE"
                          }
                        },
                        "id": "/product/web/tutum-hello-world-2",
                        "instances": 1,
                        "cpus": 0.25,
                        "mem": 256,
                        "uris": [],
                        "constraints": [["hostname", "LIKE", "server1.localnet.net"]]

                }
        ]
}

I want to increase the value of "instances": to 2 and use "constraints": [["hostname", "LIKE", "server1.localnet.net"]]. I tried different permutations, but I am getting No JSON object could be decoded over and over again :(

Using just instances: is pretty easy:

root@node108:~# http -v PUT http://10.10.10.219:8080/v2/apps/product/web/tutum-hello-world-1 instances:=1
PUT /v2/apps/product/web/tutum-hello-world-1 HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Length: 16
Content-Type: application/json; charset=utf-8
Host: 10.9.158.219:8080
User-Agent: HTTPie/0.8.0

{
    "instances": 1
}

HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Content-Length: 92
Content-Type: application/json
Expires: 0
Pragma: no-cache
Server: Jetty(8.y.z-SNAPSHOT)

{
    "deploymentId": "6eeda6ac-2ec1-4554-95f3-a0dc19333c56", 
    "version": "2015-06-10T11:33:53.165Z"
}

...however using it TOGETHER with constraints directive + nested values has proven to be difficult (for me). Any help, please ???

Thanks!!!!

from httpie.

jkbrzt avatar jkbrzt commented on April 28, 2024

@lastcoolnameleft yes, I was just bookmarking that spec. Sorry for the confusion.

from httpie.

Maatary avatar Maatary commented on April 28, 2024

Hi, I am not sure to understand, how do you provided nested json object with Httpie

from httpie.

rubemz avatar rubemz commented on April 28, 2024

any updates on this issue?
I'd also prefer what @akvadrako suggested

from httpie.

odusseys avatar odusseys commented on April 28, 2024

agree that this would be very welcome.

from httpie.

merwok avatar merwok commented on April 28, 2024

Many that I write :)

Thanks for the pointers to jarg and jo! Goes well in my json toolbox with jq and gron.

from httpie.

merwok avatar merwok commented on April 28, 2024

+1 for the compat issue, but the proposed solution should be more complicated:

$ http httpbin.org/post "foo\.bar=baz"

otherwise the shell escape \. is interpreted by the shell as . and the backslash is not passed to the command called.

from httpie.

jkbrzt avatar jkbrzt commented on April 28, 2024

@merwok Good point. Iโ€™ve updated the example to take shell escaping into account. General request item escaping rules apply.

from httpie.

BoboTiG avatar BoboTiG commented on April 28, 2024

Note that since HTTPie 2.5.0, you can use --raw in the same way you do curl -d:

$ http pie.dev/post --raw '{"foo": {"bar": "baz"}}'
{
    "foo": {
        "bar": "baz"
    }
}

from httpie.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.