mirror of
https://github.com/actix/examples
synced 2024-11-27 16:02:57 +01:00
8186a8cfea
Co-authored-by: Igor Aleksanov <popzxc@yandex.ru> Co-authored-by: Altug Sahin <altugsahin@gmail.com> Co-authored-by: Rob Ede <robjtede@icloud.com>
36 lines
724 B
Markdown
36 lines
724 B
Markdown
A simple demo for building a `JSONRPC over HTTP` server in [actix-web](https://github.com/actix/actix-web).
|
|
|
|
# Server
|
|
|
|
```sh
|
|
cd json/jsonrpc
|
|
cargo run
|
|
# Starting server on 127.0.0.1:8080
|
|
```
|
|
|
|
# Client
|
|
|
|
**curl**
|
|
|
|
```sh
|
|
$ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "ping", "params": [], "id": 1}' http://127.0.0.1:8080
|
|
# {"jsonrpc":"2.0","result":"pong","error":null,"id":1}
|
|
```
|
|
|
|
|
|
**python**
|
|
|
|
```sh
|
|
$ python tests\test_client.py
|
|
# {'jsonrpc': '2.0', 'result': 'pong', 'error': None, 'id': 1}
|
|
```
|
|
|
|
# Methods
|
|
|
|
- `ping`: Pong immeditely
|
|
- `wait`: Wait `n` seconds, and then pong
|
|
- `get`: Get global count
|
|
- `inc`: Increment global count
|
|
|
|
See `tests\test_client.py` to get more information.
|