Server Protocol
This page is for developers who build the server side of the server integration. It describes everything the app sends and accepts. Protocol version: 1.
Overview
Section titled “Overview”The app knows a server address and a token, and nothing else about your system. Your server decides what a scan means.
| Mode | Transport | Trigger |
|---|---|---|
| HTTP push | The app sends one HTTP POST per scan. | Every scan |
| WebSocket stream | The app opens a WebSocket and sends a message per scan. | Every scan |
| WebSocket request | Same WebSocket. Your server sends a scan_request. | The next scan only, as the answer to that request |
All messages are JSON objects with a type field. Rules that apply everywhere:
- Ignore unknown fields. New optional fields can be added within version 1 without changing
protocolVersion. - Only successful reads are sent. A card that could not be read produces no message.
- The device name (set per station) is sent with every
scan,scan_response,helloandtestmessage. Every scan carries ascanId(a new UUID per scan). - Failed deliveries are not queued or retried. If your server is down, the scan is lost.
- By default the token is sent as
Authorization: Bearer <token>, and scans use the messages below. Each target can instead send the token in another place and send scans in your own JSON format. This page describes the default unless it says otherwise.
Messages from the app
Section titled “Messages from the app”Sent for every scan by HTTP push and WebSocket stream.
{ "type": "scan", "protocolVersion": 1, "scanId": "6f1c9a52-6c1e-4a59-9a43-1d1f5b0f2b7e", "device": "Reception", "reader": "ACS ACR122U PICC Interface", "uid": "04A2B3C4D5E6F7", "uidFormatted": "04:A2:B3:C4:D5:E6:F7", "uidLength": 7, "timestamp": "2026-10-28T13:45:21.123Z"}| Field | Description |
|---|---|
type | "scan". |
protocolVersion | 1. |
scanId | A new UUID for every scan. |
device | The device name from the station’s settings, or the computer’s host name if none is set. Also sent in hello and test. |
reader | The name of the reader that saw the card. |
uid | The card UID in canonical form: uppercase hex, no separators, in the order the reader returned it. It does not depend on the user’s output format settings, so rely on this field. |
uidFormatted | The UID as the user’s output format renders it (case, separator, byte order, prefix). Not meant for matching; use uid. |
uidLength | Length of the UID in bytes. |
timestamp | When the scan happened: RFC 3339 in UTC with millisecond precision and a Z suffix, as in 2026-10-28T13:45:21.123Z. |
Sent by the app right after the WebSocket connects. It tells the server which modes are on, so a server can decide whether sending scan_request makes sense.
{ "type": "hello", "protocolVersion": 1, "device": "Reception", "appVersion": "1.1.0", "modes": { "stream": true, "request": true }}The app sends hello again on the same connection if the user switches the stream or request toggle. If the device name, URL or token change, the app reconnects instead.
scan_response
Section titled “scan_response”Sent when a scan answers a scan_request. It has all fields of scan, with type set to scan_response and the added requestId.
{ "type": "scan_response", "requestId": "abc", "protocolVersion": 1, "scanId": "6f1c9a52-6c1e-4a59-9a43-1d1f5b0f2b7e", "device": "Reception", "reader": "ACS ACR122U PICC Interface", "uid": "04A2B3C4D5E6F7", "uidFormatted": "04:A2:B3:C4:D5:E6:F7", "uidLength": 7, "timestamp": "2026-10-28T13:45:21.123Z"}If stream is also on, the same scan is sent as a separate scan message right after the scan_response, with the same scanId. If HTTP push is on, it is pushed too. A server that handles both messages should use scanId to avoid processing the scan twice.
scan_request_ended
Section titled “scan_request_ended”Sent whenever a request ends without a scan answering it.
{ "type": "scan_request_ended", "requestId": "abc", "reason": "timeout" }reason | When |
|---|---|
timeout | The time limit passed. |
cancelled | The server sent scan_request_cancel, or the user switched Answer scan requests off. |
superseded | A request with a different requestId arrived and replaced this one. |
disabled | The request was refused because Answer scan requests is off. |
If the connection drops while a request is pending, the request is dropped and no message can be sent. Request again after the app reconnects (it sends a new hello).
test (HTTP only)
Section titled “test (HTTP only)”Sent by the Test button of the HTTP card. Answer with a 2xx status.
{ "type": "test", "protocolVersion": 1, "device": "Reception" }Payload templates
Section titled “Payload templates”A user can set a custom template for HTTP push and for the WebSocket. The app then sends the template, filled in, in place of the standard scan message. A server that was built for the standard messages does not need to know about this; it only matters when the user points the app at an existing endpoint.
The template is JSON text with placeholders in string values. A placeholder is {{name}}, with optional ASCII whitespace inside the braces ({{ name }}). The names are the fields of the scan message:
| Placeholder | Value | JSON type |
|---|---|---|
{{uid}} | The canonical UID. | string |
{{uidFormatted}} | The UID in the user’s output format. | string |
{{uidLength}} | The UID length in bytes. | string, or number when used as the whole value |
{{scanId}} | A new UUID per scan. | string |
{{device}} | The device name. | string |
{{reader}} | The reader name. | string |
{{timestamp}} | RFC 3339 in UTC with milliseconds and a Z suffix. | string |
Rendering rules:
- Tree substitution. The app parses the template as JSON and replaces placeholders in the string values of the parsed tree, at any depth, in objects and arrays. Because values are inserted into the tree and not into the text, a UID or device name that contains quotes or backslashes cannot break the JSON.
- Keys are never substituted. A key such as
"{{uid}}"stays literal. - Number rule. A string value that is exactly one
{{uidLength}}becomes a JSON number. Every other placeholder, and{{uidLength}}inside longer text, produces a string. Other value types in the template (numbers, booleans,null) are sent as they are. - Text around placeholders is kept, so
"badge-{{uid}}"becomes"badge-04A2B3C4D5E6F7". - Key order is kept as written in the template.
- Not a placeholder: braces that do not enclose a valid name, such as
{{}},{{ 1 }},{ {uid} }or an unclosed{{uid, stay literal text. A name has letters, digits and underscores and does not start with a digit. - Limits and errors. The template is at most 8192 bytes in UTF-8. A template that is too large, is not valid JSON or names a placeholder other than the seven above is rejected when the user saves it, and the app never sends it.
- The app adds nothing to the rendered JSON: no
type, noprotocolVersion.
Example. The template {"badge": "{{uid}}", "terminal": "{{device}}", "len": "{{uidLength}}"} produces:
{ "badge": "04A2B3C4D5E6F7", "terminal": "Reception", "len": 7 }Where it applies:
| Message | With a template |
|---|---|
HTTP scan | The request body is the rendered template. |
HTTP test (the Test button) | The request body is the template rendered with an example scan instead of the test message: scanId test, reader Example Reader, UID 04A1B2C3D4E5F6, and the real device name. |
WebSocket stream scan | The text frame is the rendered template. |
WebSocket scan_response | Standard, with requestId. A template never changes answers to scan requests. |
WebSocket hello, scan_request_ended, messages to the app | Standard. |
| WebSocket test (the Test button) | After hello, one frame with the template rendered with the example scan. |
If a scan answers a scan request and stream is on, your server receives the standard scan_response and, right after it, the stream frame in the template’s shape. The scanId is the same in both, if the template includes {{scanId}}.
Messages to the app
Section titled “Messages to the app”Only on the WebSocket, and only used by the request mode.
scan_request
Section titled “scan_request”Asks for the next scan.
{ "type": "scan_request", "requestId": "abc", "timeoutMs": 30000 }| Field | Description |
|---|---|
requestId | Required string. Echoed in scan_response and scan_request_ended. |
timeoutMs | Optional. How long the app waits for a card. Default 30 000 (30 s). Values are clamped to between 1 and 300 000 (5 minutes). If timeoutMs is present but is not a non-negative integer, the app ignores the whole scan_request. |
scan_request_cancel
Section titled “scan_request_cancel”Cancels the pending request with that id. The app answers with scan_request_ended and reason cancelled. A cancel for an unknown id is ignored.
{ "type": "scan_request_cancel", "requestId": "abc" }Token transports
Section titled “Token transports”Each target, HTTP push and WebSocket, sends its token in one of five ways. The default is bearer. The same transport applies to every HTTP request and, for the WebSocket, to the upgrade request.
mode | What the app sends | Settings used |
|---|---|---|
bearer | Authorization: Bearer <token> | None. |
header | <headerName>: <token>, the token as the whole header value. | headerName, default X-API-Key. |
basic | Authorization: Basic <base64(username:token)>, the token being the password. | username, default empty. |
query | The token as a query parameter of the configured URL, form-urlencoded. Existing query parameters and the fragment stay as they are. | queryParam, default token. |
none | No credential. | None. |
Details:
- With an empty token,
bearer,headerandquerysend nothing.basicis still sent when a username is set (username:with an empty password); with no username and no token it sends nothing too. - A
headerNameis an RFC 7230 token: letters, digits and! # $ % & ' * + - . ^ _ ` | ~. The namesHost,Content-Length,Content-Type,Connection,UpgradeandTransfer-Encoding, and any name that starts withSec-WebSocket-, are refused, because the transport sets them. - A
usernameis visible ASCII (!to~) without:. It may be empty. - A
queryParamis not empty and has only letters, digits and. _ ~ -. - Only the settings of the active
modeare checked and used. The others are kept so switching modes loses nothing. - Over
querythe token is part of the URL, so it is in every access log, proxy log and monitoring tool that records URLs. Prefer a header where your server allows it.
HTTP push
Section titled “HTTP push”For every scan, the app sends:
POST /api/scans HTTP/1.1Content-Type: application/jsonAuthorization: Bearer <token>User-Agent: nfc-keyboard-emulator/1.1.0with a scan message as the body, or the rendered template. The request goes to the configured URL; the path /api/scans above is only an example. The Authorization header is left out if no token is set. With another token transport the credential goes in the header, Authorization: Basic … or the URL query instead.
How the app treats your answer:
| Your response | Result in the app |
|---|---|
Any 2xx status | Success. The response body is ignored. |
401 or 403 | Token rejected. Reported separately from an unreachable server. |
Any other status, including 3xx and 5xx | Error: Server answered with HTTP n. |
| No answer within 5 seconds, or no connection | Error: Server did not answer in time, or Server unreachable. |
The app does not follow redirects. A redirect would turn the POST into a GET or send scan data to a host the user never configured, so a 3xx is reported as an HTTP status error. Always configure the final URL.
Answer quickly and do slow work after responding. Errors are reported to the user and the scan is not sent again.
WebSocket
Section titled “WebSocket”Connecting
Section titled “Connecting”- The app connects to the configured
ws://orwss://URL. Opening the connection times out after 10 seconds. - The token is sent on the HTTP upgrade request (not in a message), by default as
Authorization: Bearer <token>. With another token transport it is the configured header,Authorization: Basic …or a query parameter of the URL. Check it there, before accepting the upgrade. Answer401or403to refuse a token. - After the connection opens, the app sends
hello. - All messages are JSON in text frames. Binary frames and unknown message types are ignored.
Keepalive and reconnecting
Section titled “Keepalive and reconnecting”- The app sends a WebSocket ping every 30 seconds. Answer with the usual pong (most WebSocket libraries do this on their own).
- If the app hears nothing from the server for more than 40 seconds (one ping interval plus 10 seconds), not even a pong, it drops the connection at the next ping and reconnects. The same happens when a message cannot be written within 10 seconds. The user sees the reason
no response. This catches connections that died without being closed, for example after the computer slept or changed networks. - If the connection drops or cannot be opened, the app reconnects with exponential backoff: 1 second, doubling up to 60 seconds, each delay varied randomly by ±20 %. The backoff is only reset once a connection has stayed open for 30 seconds. A server that accepts the upgrade and then closes the connection at once is therefore retried with growing delays, not every second.
- If the upgrade is refused with 401 or 403, the app stops retrying and shows token rejected. It only tries again when the user changes the URL or token, or clicks Reconnect. A revoked station therefore does not keep hitting your server. Other failures, including other HTTP statuses, are retried.
Scan requests
Section titled “Scan requests”- Your server sends
scan_request. The app arms: the status bar shows waiting for scan and, if notifications are on, a notification appears. - The next successful scan answers it with
scan_response. That scan is not typed as keystrokes, even when typing is armed, because the user is most likely looking at the browser page that asked for it. In the app’s log it has the status Answered server request. - Only one request is pending at a time. A new
scan_requestreplaces the old one, which ends withsuperseded. Repeating the samerequestIdjust restarts the timer. - A request ends with
scan_request_endedif it times out, is cancelled, is superseded or is refused (see above). - If Answer scan requests is switched off, the app does not arm and immediately answers with
scan_request_endedand reasondisabled.
A scan that arrives while no request is pending is a normal scan: typed if typing is armed, and sent as scan if stream is on.
Delivery semantics
Section titled “Delivery semantics”Protocol version 1 has no acknowledgement. The app counts a WebSocket scan as delivered once it has been written to an open connection. A future version can add an optional acknowledgement message without a version bump, because apps ignore message types they do not know.
Config file
Section titled “Config file”Server settings can be exported and imported as a JSON file, so your server can generate a ready-made configuration for each station.
{ "$schema": "https://docs.noix.dev/nfc-keyboard-emulator/server-config.v1.schema.json", "format": "nfc-keyboard-emulator/server-config", "version": 1, "deviceName": "Reception", "http": { "enabled": true, "url": "https://example.com/api/scans", "token": "station-token", "auth": { "mode": "header", "headerName": "X-API-Key" }, "payload": { "mode": "template", "template": "{\"badge\": \"{{uid}}\", \"terminal\": \"{{device}}\", \"time\": \"{{timestamp}}\"}" } }, "ws": { "url": "wss://example.com/scanner", "token": "station-token", "stream": true, "request": true }}| Key | Type | Description |
|---|---|---|
$schema | string | Optional. Ignored by the app. |
format | string | Required. Must be nfc-keyboard-emulator/server-config. |
version | integer | Required. Must be 1. A higher version is rejected with a message asking the user to update the app. |
deviceName | string | Name sent with every scan, hello and test message. An empty string clears it, which means the computer’s host name. |
http.enabled | boolean | Switches HTTP push on or off. |
http.url | string | Empty, or an absolute http:// or https:// URL with a host. The scheme must be lowercase. |
http.token | string | Sent according to http.auth, by default as Authorization: Bearer <token>. Only visible ASCII characters (! to ~): no spaces, line breaks, control characters or non-ASCII letters. |
http.auth | object | Optional. How the token is sent; see below. |
http.payload | object | Optional. The shape of the scan; see below. |
ws.url | string | Empty, or an absolute ws:// or wss:// URL with a host. The scheme must be lowercase. Shared by stream and request mode. |
ws.token | string | Sent according to ws.auth on the upgrade request, by default as Authorization: Bearer <token>. Same characters as http.token. |
ws.auth | object | Optional. Same as http.auth. |
ws.payload | object | Optional. Same as http.payload. Applies to streamed scans only. |
ws.stream | boolean | Send every scan over the WebSocket. |
ws.request | boolean | Answer scan requests. |
Strings are trimmed of surrounding whitespace, except payload.template. Unknown keys are ignored. A file that is not JSON, has another format, or contains an invalid URL, a token with other characters, or an invalid auth or payload value is rejected as a whole.
Auth and payload
Section titled “Auth and payload”auth and payload have the same shape in http and ws.
| Key | Type | Description |
|---|---|---|
auth.mode | string | bearer (default), header, basic, query or none. See token transports. |
auth.headerName | string | The header for header mode. Default X-API-Key. |
auth.username | string | The user name for basic mode. Default empty. |
auth.queryParam | string | The parameter for query mode. Default token. |
payload.mode | string | standard (default) or template. |
payload.template | string | The JSON text of the template, with {{placeholders}}. At most 8192 bytes. Used in template mode and kept otherwise. See payload templates. |
The rules for these keys, and for a present or absent object:
- A present
authorpayloadobject replaces the whole setting. Keys missing from the object take their defaults; they do not keep the user’s previous value. To change only the mode, send the object with the other values you want to keep. - An absent object leaves the setting as it is.
- Only the settings of the selected mode are checked: a bad
headerNameis fine whileauth.modeisbearer, and the template is only checked whilepayload.modeistemplate. An invalid value for the selected mode, or a template that is too large, not valid JSON or has an unknown placeholder, rejects the whole file. - A value of the wrong type, or an unknown
mode, rejects the whole file. - The token still belongs to
token. Inbasicmode it is the password. - Switching a target with a kept token to
querycounts as sending the token somewhere new: the user sees the warning that the stored token will be sent to the address.
Older versions of the app know neither key and ignore them: the import then sets the URL and token as before and the target keeps using a bearer token and the standard message. The keys are optional, so version stays 1.
Absent versus empty
Section titled “Absent versus empty”Every key except format and version is optional, and so is every key inside http and ws.
- Absent key or section: that setting stays as it is.
- Present key: the setting is replaced, even with an empty string.
To clear a value, send it explicitly, for example "token": "". This lets you change a URL without sending the token again:
{ "format": "nfc-keyboard-emulator/server-config", "version": 1, "http": { "url": "https://new.example.com/api/scans" }}The user always sees a preview of the result and must confirm before anything is applied. Tokens are never shown in the preview, only whether they stay unchanged, are set, or are cleared. The preview shows each server address before and after the import, and warns when a stored token would be sent to a different address, or when https:// or wss:// would become http:// or ws://. To move a station to a new server without that warning, send the new token along with the new URL.
Export writes all keys, including the tokens, and always both auth and payload of each target, with every field, so an exported file is a complete snapshot of the setup. Importing it on another station reproduces that setup exactly.
JSON Schema
Section titled “JSON Schema”The schema for version 1 is published at:
https://docs.noix.dev/nfc-keyboard-emulator/server-config.v1.schema.jsonUse it to validate the files you generate.
Configuration link
Section titled “Configuration link”A web page can apply a configuration by linking to the app:
nfc-keyboard-emulator://configure?config=<base64url(JSON)><base64url(JSON)> is the config file above, UTF-8 encoded and written in URL-safe Base64 (- and _ instead of + and /) without = padding. The app also accepts the standard alphabet and padding, but generate the URL-safe form.
Opening the link starts the app, or brings the running app to the front, and shows the same preview as a file import. Nothing is applied without the user’s confirmation. If the link cannot be decoded, the app shows This link is not a valid server configuration. If it decodes but the configuration is invalid, the app shows the same errors as for a file import (wrong format, unsupported version, invalid URL). The app must be installed for the link to work, and the browser may ask the user before opening it.
// Builds a configuration link for one station.function configLink(config) { const bytes = new TextEncoder().encode(JSON.stringify(config)); const binary = Array.from(bytes, (b) => String.fromCharCode(b)).join(""); const base64url = btoa(binary) .replace(/\+/g, "-") .replace(/\//g, "_") .replace(/=+$/, ""); return `nfc-keyboard-emulator://configure?config=${base64url}`;}
const href = configLink({ format: "nfc-keyboard-emulator/server-config", version: 1, deviceName: "Reception", ws: { url: "wss://example.com/scanner", token: "station-token", stream: true, request: true, },});Example server
Section titled “Example server”A small Node.js server that handles HTTP push, stream and scan requests, with a demo page, is in the app repository: examples/server. It needs Node.js 22 or newer.
cd examples/servernpm installTOKEN=dev node server.mjsThe server listens on 127.0.0.1:8787 only. Open http://localhost:8787/ for the demo page and enter these in the app’s Server view, using dev as the token:
| Mode | URL |
|---|---|
| HTTP push | http://localhost:8787/scans |
| WebSocket (stream and request) | ws://localhost:8787/scanner |
In the demo page, click Scan and hold a card to the reader to see a request being answered. The comments in server.mjs explain each protocol rule. It is reference code, not production code: the page’s own socket has no authentication and all state is kept in memory.
Security notes for integrators
Section titled “Security notes for integrators”- Issue one token per station (or per user), so you can tell stations apart and revoke one without touching the others. Compare tokens in constant time.
- Check the token before anything else: on the HTTP request, and on the WebSocket upgrade request. Answer
401or403; the app reports it as a rejected token and stops reconnecting. - Use
https://andwss://. Overhttp://andws://the token travels in clear text. - Prefer a header to a URL parameter. With the
querytransport the token is part of the URL, which access logs, proxies and monitoring tools record. If you must accept it, strip the parameter from your logs. The app never writes the URL’s query into its own errors or log. - Generate configuration links on demand for the logged-in user. A link carries a token, so do not store links, put them in emails, or share them. Prefer short-lived or single-use tokens where you can.
- Never log tokens, in the
Authorizationheader, in config files or in links. The same goes for access logs that record URLs, if you put a token in a link. - Treat
uidas data, not as proof. A UID is an identifier and can be cloned. Decide on the server which user a token belongs to and what that user may do. - Validate input. Ignore unknown fields, and reject messages that do not match the shape you expect.