2016-05-13 6 views

risposta

28

È possibile pass the whole JSON via stdin:

$ echo '{ "user": { "name": "john", "age": 10 } }' | http httpbin.org/post 

O specify the raw JSON as value with :=:

$ http httpbin.org/post user:='{"name": "john", "age": 10 }' 
+0

Che dire se il nome è in realtà un oggetto json e non un tavolo. Quindi all'interno dell'utente che nome: {"id": "x", "fn": "xx"} – MaatDeamon

+0

Cosa intendi per "tabella"? In entrambi gli esempi sopra HTTPie invia l'oggetto JSON dalla tua domanda. –

+0

Scusa per tabella intendevo array – MaatDeamon

17

Mi piace questo modo:

$ http PUT localhost:8080/user <<<'{ "user": { "name": "john" "age": 10 }}' 

È preferibile perché ha lo stesso prefisso, come i comandi correlati, e quindi è conveniente per trovare i comandi con Ctrl+R in bash:

$ http localhost:8080/user/all 
$ http GET localhost:8080/user/all # the same as the previous 
$ http DELETE localhost:8080/user/234 
+0

Sembra che questa soluzione non funzioni in Windows –