run prettier formatter on some readme files

This commit is contained in:
Simon Laux
2024-11-02 14:53:49 +01:00
parent f302ce92de
commit aff063e893
2 changed files with 23 additions and 16 deletions

View File

@@ -4,8 +4,8 @@ This crate provides a [JSON-RPC 2.0](https://www.jsonrpc.org/specification) inte
The JSON-RPC API is exposed in two fashions: The JSON-RPC API is exposed in two fashions:
* A executable that exposes the JSON-RPC API through a [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) server running on localhost. - A executable that exposes the JSON-RPC API through a [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) server running on localhost.
* The JSON-RPC API can also be called through the [C FFI](../deltachat-ffi). The C FFI needs to be built with the `jsonrpc` feature. It will then expose the functions `dc_jsonrpc_init`, `dc_jsonrpc_request`, `dc_jsonrpc_next_response` and `dc_jsonrpc_unref`. See the docs in the [header file](../deltachat-ffi/deltachat.h) for details. - The JSON-RPC API can also be called through the [C FFI](../deltachat-ffi). The C FFI needs to be built with the `jsonrpc` feature. It will then expose the functions `dc_jsonrpc_init`, `dc_jsonrpc_request`, `dc_jsonrpc_next_response` and `dc_jsonrpc_unref`. See the docs in the [header file](../deltachat-ffi/deltachat.h) for details.
We also include a JavaScript and TypeScript client for the JSON-RPC API. The source for this is in the [`typescript`](typescript) folder. The client can easily be used with the WebSocket server to build DeltaChat apps for web browsers or Node.js. See the [examples](typescript/example) for details. We also include a JavaScript and TypeScript client for the JSON-RPC API. The source for this is in the [`typescript`](typescript) folder. The client can easily be used with the WebSocket server to build DeltaChat apps for web browsers or Node.js. See the [examples](typescript/example) for details.
@@ -24,16 +24,17 @@ If you want to use the server in a production setup, first build it in release m
```sh ```sh
cargo build --features webserver --release cargo build --features webserver --release
``` ```
You will then find the `deltachat-jsonrpc-server` executable in your `target/release` folder. You will then find the `deltachat-jsonrpc-server` executable in your `target/release` folder.
The executable currently does not support any command-line arguments. By default, once started it will accept WebSocket connections on `ws://localhost:20808/ws`. It will store the persistent configuration and databases in a `./accounts` folder relative to the directory from where it is started. The executable currently does not support any command-line arguments. By default, once started it will accept WebSocket connections on `ws://localhost:20808/ws`. It will store the persistent configuration and databases in a `./accounts` folder relative to the directory from where it is started.
The server can be configured with environment variables: The server can be configured with environment variables:
|variable|default|description| | variable | default | description |
|-|-|-| | ------------------ | ------------ | ------------------------- |
|`DC_PORT`|`20808`|port to listen on| | `DC_PORT` | `20808` | port to listen on |
|`DC_ACCOUNTS_PATH`|`./accounts`|path to storage directory| | `DC_ACCOUNTS_PATH` | `./accounts` | path to storage directory |
If you are targeting other architectures (like KaiOS or Android), the webserver binary can be cross-compiled easily with [rust-cross](https://github.com/cross-rs/cross): If you are targeting other architectures (like KaiOS or Android), the webserver binary can be cross-compiled easily with [rust-cross](https://github.com/cross-rs/cross):
@@ -46,29 +47,32 @@ cross build --features=webserver --target armv7-linux-androideabi --release
The package includes a JavaScript/TypeScript client which is partially auto-generated through the JSON-RPC library used by this crate ([yerpc](https://github.com/Frando/yerpc/)). Find the source in the [`typescript`](typescript) folder. The package includes a JavaScript/TypeScript client which is partially auto-generated through the JSON-RPC library used by this crate ([yerpc](https://github.com/Frando/yerpc/)). Find the source in the [`typescript`](typescript) folder.
To use it locally, first install the dependencies and compile the TypeScript code to JavaScript: To use it locally, first install the dependencies and compile the TypeScript code to JavaScript:
```sh ```sh
cd typescript cd typescript
npm install npm install
npm run build npm run build
``` ```
The package is also published on npm under the name [`@deltachat/jsonrpc-client`](https://www.npmjs.com/package/@deltachat/jsonrpc-client). The package is also published on npm under the name [`@deltachat/jsonrpc-client`](https://www.npmjs.com/package/@deltachat/jsonrpc-client).
###### Usage ###### Usage
Stdio server (recommended): Stdio server (recommended):
```typescript ```typescript
import { startDeltaChat } from "@deltachat/stdio-rpc-server"; import { startDeltaChat } from "@deltachat/stdio-rpc-server";
import { C } from "@deltachat/jsonrpc-client"; import { C } from "@deltachat/jsonrpc-client";
const dc = await startDeltaChat("deltachat-data"); const dc = await startDeltaChat("deltachat-data");
console.log(await dc.rpc.getSystemInfo()); console.log(await dc.rpc.getSystemInfo());
const accounts = await dc.rpc.getAllAccounts() const accounts = await dc.rpc.getAllAccounts();
console.log('accounts', accounts) console.log("accounts", accounts);
dc.close() dc.close();
``` ```
Websocket: Websocket:
```typescript ```typescript
import { WebsocketDeltaChat as DeltaChat } from '@deltachat/jsonrpc-client''= import { WebsocketDeltaChat as DeltaChat } from '@deltachat/jsonrpc-client''=
@@ -81,10 +85,12 @@ console.log('accounts', accounts)
##### Generate TypeScript/JavaScript documentation ##### Generate TypeScript/JavaScript documentation
A script is included to build autogenerated documentation, which includes all RPC methods: A script is included to build autogenerated documentation, which includes all RPC methods:
```sh ```sh
cd typescript cd typescript
npm run docs npm run docs
``` ```
Then open the [`typescript/docs`](typescript/docs) folder in a web browser. Then open the [`typescript/docs`](typescript/docs) folder in a web browser.
## Development ## Development
@@ -99,6 +105,7 @@ npm run build
npm run example:build npm run example:build
npm run example:start npm run example:start
``` ```
Then, open [`http://localhost:8080/example.html`](http://localhost:8080/example.html) in a web browser. Then, open [`http://localhost:8080/example.html`](http://localhost:8080/example.html) in a web browser.
Run `npm run example:dev` to live-rebuild the example app when files changes. Run `npm run example:dev` to live-rebuild the example app when files changes.

View File

@@ -18,11 +18,11 @@ import { startDeltaChat } from "@deltachat/stdio-rpc-server";
import { C } from "@deltachat/jsonrpc-client"; import { C } from "@deltachat/jsonrpc-client";
async function main() { async function main() {
const dc = await startDeltaChat("deltachat-data"); const dc = await startDeltaChat("deltachat-data");
console.log(await dc.rpc.getSystemInfo()); console.log(await dc.rpc.getSystemInfo());
dc.close() dc.close();
} }
main() main();
``` ```
For a more complete example refer to https://github.com/deltachat-bot/echo/tree/master/nodejs_stdio_jsonrpc. For a more complete example refer to https://github.com/deltachat-bot/echo/tree/master/nodejs_stdio_jsonrpc.