Skip to content

Commit d2d40eb

Browse files
jkbrztisidentical
andauthored
Finish docs for v3.0.0 (#1269)
* WIP * Rewrite the introduction segment of the Nested JSON Co-authored-by: Batuhan Taskaya <[email protected]>
1 parent cd877a5 commit d2d40eb

File tree

2 files changed

+77
-107
lines changed

2 files changed

+77
-107
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
55

66
## [3.0.0.dev0](https://github.com/httpie/httpie/compare/2.6.0...master) (unreleased)
77

8-
- Drop support for Python 3.6. ([#1177](https://github.com/httpie/httpie/issues/1177))
8+
- Dropped support for Python 3.6. ([#1177](https://github.com/httpie/httpie/issues/1177))
99
- Improved startup time by 40%. ([#1211](https://github.com/httpie/httpie/pull/1211))
1010
- Added support for nested JSON syntax. ([#1169](https://github.com/httpie/httpie/issues/1169))
1111
- Added `httpie plugins` interface for plugin management. ([#566](https://github.com/httpie/httpie/issues/566))
@@ -15,12 +15,12 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1515
- Added support for _receiving_ multiple HTTP headers lines with the same name. ([#1207](https://github.com/httpie/httpie/issues/1207))
1616
- Added support for basic JSON types on `--form`/`--multipart` when using JSON only operators (`:=`/`:=@`). ([#1212](https://github.com/httpie/httpie/issues/1212))
1717
- Added support for automatically enabling `--stream` when `Content-Type` is `text/event-stream`. ([#376](https://github.com/httpie/httpie/issues/376))
18-
- Added support for displaying the total elapsed time throguh `--meta`/`-vv` or `--print=m`. ([#243](https://github.com/httpie/httpie/issues/243))
18+
- Added support for displaying the total elapsed time through `--meta`/`-vv` or `--print=m`. ([#243](https://github.com/httpie/httpie/issues/243))
1919
- Added new `pie-dark`/`pie-light` (and `pie`) styles that match with [HTTPie for Web and Desktop](https://httpie.io/product). ([#1237](https://github.com/httpie/httpie/issues/1237))
2020
- Added support for better error handling on DNS failures. ([#1248](https://github.com/httpie/httpie/issues/1248))
2121
- Added support for storing prompted passwords in the local sessions. ([#1098](https://github.com/httpie/httpie/issues/1098))
2222
- Added warnings about the `--ignore-stdin`, when there is no incoming data from stdin. ([#1255](https://github.com/httpie/httpie/issues/1255))
23-
- Broken plugins will no longer crash the whole application. ([#1204](https://github.com/httpie/httpie/issues/1204))
23+
- Fixed crashing due to broken plugins. ([#1204](https://github.com/httpie/httpie/issues/1204))
2424
- Fixed auto addition of XML declaration to every formatted XML response. ([#1156](https://github.com/httpie/httpie/issues/1156))
2525
- Fixed highlighting when `Content-Type` specifies `charset`. ([#1242](https://github.com/httpie/httpie/issues/1242))
2626
- Fixed an unexpected crash when `--raw` is used with `--chunked`. ([#1253](https://github.com/httpie/httpie/issues/1253))

docs/README.md

Lines changed: 74 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ Content-Type: application/json
598598
599599
## JSON
600600
601-
JSON is the *lingua franca* of modern web services and it is also the **implicit content type** HTTPie uses by default.
601+
JSON is the *lingua franca* of modern web services, and it is also the **implicit content type** HTTPie uses by default.
602602
603603
Simple example:
604604
@@ -624,7 +624,7 @@ Host: pie.dev
624624
If your command includes some data [request items](#request-items), they are serialized as a JSON object by default. HTTPie also automatically sets the following headers, both of which can be overwritten:
625625
626626
| Header | Value |
627-
| -------------: | ----------------------------- |
627+
|---------------:|-------------------------------|
628628
| `Content-Type` | `application/json` |
629629
| `Accept` | `application/json, */*;q=0.5` |
630630
@@ -677,132 +677,106 @@ The `:=`/`:=@` syntax is JSON-specific. You can switch your request to `--form`
677677
and string, float, and number values will continue to be serialized (as string form values).
678678
Other JSON types, however, are not allowed with `--form` or `--multipart`.
679679
680-
### Nested JSON fields
680+
### Nested JSON
681681
682-
In the past (pre-3.0), HTTPie's data operators (`=`/`:=`) allowed you to
683-
directly create basic JSON objects right from your terminal. Though this
684-
functionality was limited to only top-level keys.
685-
686-
```bash
687-
$ http --offline --print=B pie.dev/post \
688-
type=success
689-
```
690-
691-
```json
692-
{
693-
"type": "success"
694-
}
695-
```
696-
697-
For embedding more complex JSON objects, you needed to use the `:=` operator.
698-
699-
```bash
700-
$ http --offline --print=B pie.dev/post \
701-
type=success \
702-
'product:={"name":"something", "price":10}'
703-
```
704-
705-
```json
706-
{
707-
"product": {
708-
"name": "something",
709-
"price": 10
710-
},
711-
"type": "success"
712-
}
713-
```
714-
715-
Starting with 3.0, we have created a mini language in HTTPie's own syntax to
716-
build complex JSON objects with ease. This syntax was inspired by the [JSON form](https://www.w3.org/TR/html-json-forms/)
717-
proposal for HTML, though we have changed a lot of parts to offer the best experience.
682+
If your use case involves sending complex JSON objects as part of the request body,
683+
HTTPie can help you build them right from your terminal. You still use the existing
684+
data field operators (`=`/`:=`) but instead of specifying a top-level field name (like `key=value`), you specify a path declaration. This tells HTTPie where and how to put the given value inside of an object.
718685
719686
#### Introduction
720687
721-
Let's start with a simple introduction, and build the JSON object we have seen in the example
722-
above:
688+
Let's start with a simple example, and build a simple search query:
723689
724690
```bash
725691
$ http --offline --print=B pie.dev/post \
726-
type=success \
727-
product[name]=something \
728-
product[price]:=10
692+
category=tools \
693+
search[type]=id \
694+
search[id]:=1
729695
```
730696
731-
With the new syntax, you can designate the path for the value. For example `product[name]` means
732-
create a new object under the `product` key, and set the `name` field of that object to the given
733-
value.
697+
In the example above, the `search[type]` is an instruction for creating an object called `search`, and setting the `type` field of it to the given value (`"id"`).
698+
699+
Also note that, just as the regular syntax, you can use the `:=` operator to directly pass raw JSON values (e.g numbers in the case above).
734700
735701
```json
736702
{
737-
"product": {
738-
"name": "something",
739-
"price": 10
740-
},
741-
"type": "success"
703+
"category": "tools",
704+
"search": {
705+
"id": 1,
706+
"type": "id"
707+
}
742708
}
743709
```
744710
745-
You can also build arrays, through `[]` suffix. Which means create a list, and append the value
746-
to that list:
711+
Building arrays is also possible, through `[]` suffix (an append operation). This tells HTTPie to create an array in the given path (if there is not one already), and append the given value to that array.
747712
748713
```bash
749714
$ http --offline --print=B pie.dev/post \
750-
search[keywords][]=soda \
751-
search[keywords][]=fries
715+
category=tools \
716+
search[type]=keyword \
717+
search[keywords][]=APIs \
718+
search[keywords][]=CLI
752719
```
753720
754721
```json
755722
{
723+
"category": "tools",
756724
"search": {
757725
"keywords": [
758-
"soda",
759-
"fries"
760-
]
726+
"APIs",
727+
"CLI"
728+
],
729+
"type": "keyword"
761730
}
762731
}
763732
```
764733
765-
If you want to specify the direct index, that is also supported:
734+
If you want to explicitly specify the position of elements inside an array,
735+
you can simply pass the desired index as the path:
766736
767737
```bash
768738
$ http --offline --print=B pie.dev/post \
769-
search[keywords][0]=soda \
770-
search[keywords][1]=fries
739+
category=tools \
740+
search[type]=keyword \
741+
search[keywords][1]=APIs \
742+
search[keywords][2]=CLI
771743
```
772744
773745
```json
774746
{
747+
"category": "tools",
775748
"search": {
776749
"keywords": [
777-
"soda",
778-
"fries"
779-
]
750+
"CLIs",
751+
"API"
752+
],
753+
"type": "keyword"
780754
}
781755
}
782756
```
783757
784-
You can also create 'sparse arrays' (arrays where you set 2 non-consecutive indexes), which
785-
the missing values gets nullified:
758+
If there are any missing indexes, HTTPie will nullify them in order to create a concrete object that can be sent:
786759
787760
```bash
788761
$ http --offline --print=B pie.dev/post \
789-
search[keywords][2]=soda \
790-
search[keywords][5]=fries \
791-
search[keywords][]=fish
762+
category=tools \
763+
search[type]=platforms \
764+
search[platforms][]=Terminal \
765+
search[platforms][1]=Desktop \
766+
search[platforms][3]=Mobile
792767
```
793768
794769
```json
795770
{
771+
"category": "tools",
796772
"search": {
797-
"keywords": [
798-
null,
799-
null,
800-
"soda",
773+
"platforms": [
774+
"Terminal",
775+
"Desktop",
801776
null,
802-
null,
803-
"fries",
804-
"fish"
805-
]
777+
"Mobile"
778+
],
779+
"type": "platforms"
806780
}
807781
}
808782
```
@@ -811,27 +785,29 @@ It is also possible to embed raw JSON to a nested structure, for example:
811785
812786
```bash
813787
$ http --offline --print=B pie.dev/post \
814-
invitation[type]=meetup \
815-
'invitation[dates]:=[2021, 2022, 2023, 2024]' \
816-
invitation[dates][]:=2025
788+
category=tools \
789+
search[type]=platforms \
790+
'search[platforms]:=["Terminal", "Desktop"]' \
791+
search[platforms][]=Web \
792+
search[platforms][]=Mobile
817793
```
818794
819795
```json
820796
{
821-
"invitation": {
822-
"dates": [
823-
2021,
824-
2022,
825-
2023,
826-
2024,
827-
2025
797+
"category": "tools",
798+
"search": {
799+
"platforms": [
800+
"Terminal",
801+
"Desktop",
802+
"Web",
803+
"Mobile"
828804
],
829-
"type": "meetup"
805+
"type": "platforms"
830806
}
831807
}
832808
```
833809
834-
And for the last, let's create a very deeply nested JSON object:
810+
And just to demonstrate all of these features together, let's create a very deeply nested JSON object:
835811
836812
```bash
837813
$ http PUT pie.dev/put \
@@ -843,11 +819,11 @@ $ http PUT pie.dev/put \
843819
very[nested][json][3][httpie][power][]=Amaze # Nested object
844820
```
845821
846-
#### Advanced Usage
822+
#### Advanced usage
847823
848-
##### Escaping Behavior
824+
##### Escaping behavior
849825
850-
Nested JSON syntax uses the same escaping rules [escaping rules](escaping-rules) as
826+
Nested JSON syntax uses the same [escaping rules](#escaping-rules) as
851827
the terminal. There are 3 special characters, and 1 special token that you can escape.
852828
853829
If you want to send a bracket as is, escape it with a backslash (`\`):
@@ -907,7 +883,7 @@ $ http --offline --print=B pie.dev/post \
907883
}
908884
```
909885
910-
##### Guiding Syntax Errors
886+
##### Guiding syntax errors
911887
912888
If you make a typo or forget to close a bracket, the errors will guide you to fix it. For example:
913889
@@ -925,7 +901,7 @@ foo[baz][quux
925901
926902
You can follow to given instruction (adding a `]`) and repair your expression.
927903
928-
##### Type Safety
904+
##### Type safety
929905
930906
Each container path (e.g `x[y][z]` in `x[y][z][1]`) has a certain type, which gets defined with
931907
the first usage and can't be changed after that. If you try to do a key-based access to an array or
@@ -959,18 +935,12 @@ $ http --offline --print=B pie.dev/post \
959935
960936
### Raw JSON
961937
962-
Please note that on some very complex JSON structures, manually building the JSON object right from the terminal
963-
might be more complicated compared to typing it on a file and directly sending it through HTTPie. Depending on your
964-
use case, some of the following examples can help:
938+
For very complex JSON structures, it may be more convenient to [pass it as raw request body](#raw-request-body), for example:
965939
966940
```bash
967941
$ echo -n '{"hello": "world"}' | http POST pie.dev/post
968942
```
969943
970-
```bash
971-
$ http --raw '{"hello": "world"}' POST pie.dev/post
972-
```
973-
974944
```bash
975945
$ http POST pie.dev/post < files/data.json
976946
```
@@ -1253,7 +1223,7 @@ the [sessions](#sessions) feature.
12531223
The currently supported authentication schemes are Basic and Digest (see [auth plugins](#auth-plugins) for more). There are two flags that control authentication:
12541224
12551225
| Flag | Arguments |
1256-
| ----------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1226+
|------------------:|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
12571227
| `--auth, -a` | Pass either a `username:password` pair or a `token` as the argument. If the selected authenticated method requires username/password combination and if you only specify a username (`-a username`), you’ll be prompted for the password before the request is sent. To send an empty password, pass `username:`. The `username:password@hostname` URL syntax is supported as well (but credentials passed via `-a` have higher priority) |
12581228
| `--auth-type, -A` | Specify the auth mechanism. Possible values are `basic`, `digest`, `bearer` or the name of any [auth plugins](#auth-plugins) you have installed. The default value is `basic` so it can often be omitted |
12591229
@@ -1592,7 +1562,7 @@ The response headers are downloaded always, even if they are not part of the out
15921562
In addition to crafting structured [JSON](#json) and [forms](#forms) requests with the [request items](#request-items) syntax, you can provide a raw request body that will be sent without further processing.
15931563
These two approaches for specifying request data (i.e., structured and raw) cannot be combined.
15941564
1595-
There’re three methods for passing raw request data: piping via `stdin`,
1565+
There are three methods for passing raw request data: piping via `stdin`,
15961566
`--raw='data'`, and `@/file/path`.
15971567
15981568
### Redirected Input

0 commit comments

Comments
 (0)