Files
chatmail-core/deltachat-jsonrpc/README.md
Franz Heinzmann (Frando) 035e208e4f Improve docs.
2022-07-05 15:50:03 +02:00

2.8 KiB

deltachat-jsonrpc

This crate provides a JSON-RPC 2.0 interface to DeltaChat.

The JSON-RPC API is exposed in two fashions:

  • The JSON-RPC API can be called through the C FFI with the functions dc_jsonrpc_init, dc_jsonrpc_request, dc_jsonrpc_next_response and dc_jsonrpc_unref.
  • This crate includes a binary that serves the JSON-RPC API over a WebSocket.

We also include a JavaScript and TypeScript client for the JSON-RPC API. The source for this is in the typescript folder and published on NPM as deltachat-jsonrpc.

Usage

Running the WebSocket server

From within this folder, you can start the WebSocket server with the following command:

cargo run --features webserver

The server accepts WebSocket connections on ws://localhost:20808/ws.

If you are targetting other architectures (like KaiOS or Android), the webserver binary can be cross-compiled easily with rust-cross:

cross build --features=webserver --target armv7-linux-androideabi --release

Running the example app

We include a small demo web application that talks to the WebSocket server. To run it, follow these steps:

  • The package includes TypeScript bindings which are partially auto-generated through the JSON-RPC library used by this crate (yerpc).

    cd typescript
    npm install
    npm run build
    
  • Then, build and run the example application:

    npm run example:dev
    

Compiling server for kaiOS or android:

Run the tests

Rust tests

cargo test --features=webserver

Typescript

cd typescript
npm run test

For the online tests to run you need a test account token for a mailadm instance, you can use docker to spin up a local instance: https://github.com/deltachat/docker-mailadm

set the env var DCC_NEW_TMP_EMAIL to your mailadm token: example: DCC_NEW_TMP_EMAIL=https://testrun.org/new_email?t=1h_195dksa6544

If your test fail with server shutdown at the start, then you might have a process from a last run still running probably and you need to kill that process manually to continue.

Test Coverage

You can test coverage with npm run coverage, but you need to have DCC_NEW_TMP_EMAIL set, otherwise the result will be useless because some functions can only be tested with the online tests.

If you are offline and want to see the coverage results anyway (even though they are NOT correct), you can bypass the error with COVERAGE_OFFLINE=1 npm run coverage

Open coverage/index.html for a detailed report. bindings.ts is probably the most interesting file for coverage, because it describes the api functions.