Skip to content

Commit 63cc92e

Browse files
committed
Adjust docs/requests.md
1 parent 0605fc5 commit 63cc92e

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

docs/requests.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,44 @@
55
Generate a request with the `request` function:
66

77
```python
8-
>>> from jsonrpcclient import request
8+
>>> from jsonrpcclient import request, request_json
99
>>> request("ping")
10-
{"jsonrpc": "2.0", "method": "ping", "2.0", "id": 1}
10+
{'jsonrpc': '2.0', 'method': 'ping', 'id': 1}
1111
```
1212

13+
`request_json` gives you a string:
14+
15+
```py
16+
>>> request_json("ping")
17+
'{"jsonrpc": "2.0", "method": "ping", "id": 2}'
18+
```
19+
20+
It simply applies `str` after `request`.
21+
1322
## Ids
1423

1524
Subsequent calls increment the `id`:
25+
1626
```
17-
>>> request("ping")
18-
{"jsonrpc": "2.0", "method": "ping", "2.0", "id": 2}
19-
>>> request("ping")
20-
{"jsonrpc": "2.0", "method": "ping", "2.0", "id": 3}
27+
28+
> > > request("ping")
29+
> > > {"jsonrpc": "2.0", "method": "ping", "2.0", "id": 3}
30+
> > > request("ping")
31+
> > > {"jsonrpc": "2.0", "method": "ping", "2.0", "id": 4}
32+
2133
```
2234

2335
Use an explicit `id`:
36+
2437
```
25-
>>> request("ping", id="foo")
26-
{"jsonrpc": "2.0", "method": "ping", "2.0", "id": "foo"}
38+
39+
> > > request("ping", id="foo")
40+
> > > {"jsonrpc": "2.0", "method": "ping", "2.0", "id": "foo"}
41+
2742
```
2843

2944
Or generate a different type of `id`:
45+
3046
```python
3147
>>> from jsonrpcclient import request_hex, request_random, request_uuid
3248
>>> request_hex("foo")
@@ -44,14 +60,15 @@ tuple for positional arguments, or dict for keyword arguments.
4460

4561
```python
4662
>>> request("ping", params=(1,))
47-
{"jsonrpc": "2.0", "method": "ping", "2.0", "params": [1], "id": 4}
63+
{"jsonrpc": "2.0", "method": "ping", "2.0", "params": [1], "id": 5}
4864
>>> request("ping", params={"key": "val"})
49-
{"jsonrpc": "2.0", "method": "ping", "2.0", "params": {"key": "val"}, "id": 5}
65+
{"jsonrpc": "2.0", "method": "ping", "2.0", "params": {"key": "val"}, "id": 6}
5066
```
5167

5268
## JSON requests
5369

5470
If you need the request serialized to a string, use `request_json`:
71+
5572
```python
5673
>>> from jsonrpcclient import request_json
5774
>>> request_json("foo")
@@ -71,14 +88,15 @@ You can also use request_json_hex etc., for the other id types.
7188
## Notifications
7289

7390
Use the `notification` function instead of `request`:
91+
7492
```python
7593
>>> from jsonrpcclient import notification
7694
>>> notification("ping")
7795
{"jsonrpc": "2.0", "method": "ping"}
7896
```
7997

80-
Similar to `request_json`, `notification_json` will give you the notification
81-
as a JSON string.
98+
As with `request_json`, `notification_json` will give you the notification as a
99+
JSON string.
82100

83101
```python
84102
>>> from jsonrpcclient import notification_json

0 commit comments

Comments
 (0)