This example demonstrates the fundamentals of using jmap-kit by connecting to a JMAP server and sending multiple Core/echo invocations in a single request.
Create a .env file in the repo root or export these variables in your shell:
JMAP_BEARER_TOKEN=your-token
JMAP_HOSTNAME=api.fastmail.com
JMAP_LOG_LEVEL=info
Clone the jmap-kit repository, then from the repo root:
yarn tsx examples/basic/basic.ts
JMAPClient with the fetch transport/.well-known/jmap on the hostCore/echo invocationsThe example builds a request with two Core/echo invocations. The serialised request body looks like:
{
"using": ["urn:ietf:params:jmap:core"],
"methodCalls": [
["Core/echo", { "arg1": "Hello", "arg2": "World" }, "id_0"],
[
"Core/echo",
{
"count": 3,
"tags": ["demo", "core", "echo"],
"nested": {
"enabled": true,
"note": "You can pass any JSON-serializable data to echo requests."
}
},
"id_1"
]
]
}
The Core/echo method simply echoes the arguments back unchanged, making it useful for testing the request/response lifecycle without side effects.
JMAP_HOSTNAME defaults to api.fastmail.com if unsetJMAP_LOG_LEVEL can be: debug, log, info, warn, error, or silent