Skip to content

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.

The app knows a server address and a token, and nothing else about your system. Your server decides what a scan means.

ModeTransportTrigger
HTTP pushThe app sends one HTTP POST per scan.Every scan
WebSocket streamThe app opens a WebSocket and sends a message per scan.Every scan
WebSocket requestSame 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, hello and test message. Every scan carries a scanId (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.

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"
}
FieldDescription
type"scan".
protocolVersion1.
scanIdA new UUID for every scan.
deviceThe device name from the station’s settings, or the computer’s host name if none is set. Also sent in hello and test.
readerThe name of the reader that saw the card.
uidThe 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.
uidFormattedThe UID as the user’s output format renders it (case, separator, byte order, prefix). Not meant for matching; use uid.
uidLengthLength of the UID in bytes.
timestampWhen 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.

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.

Sent whenever a request ends without a scan answering it.

{ "type": "scan_request_ended", "requestId": "abc", "reason": "timeout" }
reasonWhen
timeoutThe time limit passed.
cancelledThe server sent scan_request_cancel, or the user switched Answer scan requests off.
supersededA request with a different requestId arrived and replaced this one.
disabledThe 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).

Sent by the Test button of the HTTP card. Answer with a 2xx status.

{ "type": "test", "protocolVersion": 1, "device": "Reception" }

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:

PlaceholderValueJSON 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, no protocolVersion.

Example. The template {"badge": "{{uid}}", "terminal": "{{device}}", "len": "{{uidLength}}"} produces:

{ "badge": "04A2B3C4D5E6F7", "terminal": "Reception", "len": 7 }

Where it applies:

MessageWith a template
HTTP scanThe 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 scanThe text frame is the rendered template.
WebSocket scan_responseStandard, with requestId. A template never changes answers to scan requests.
WebSocket hello, scan_request_ended, messages to the appStandard.
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}}.

Only on the WebSocket, and only used by the request mode.

Asks for the next scan.

{ "type": "scan_request", "requestId": "abc", "timeoutMs": 30000 }
FieldDescription
requestIdRequired string. Echoed in scan_response and scan_request_ended.
timeoutMsOptional. 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.

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" }

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.

modeWhat the app sendsSettings used
bearerAuthorization: Bearer <token>None.
header<headerName>: <token>, the token as the whole header value.headerName, default X-API-Key.
basicAuthorization: Basic <base64(username:token)>, the token being the password.username, default empty.
queryThe token as a query parameter of the configured URL, form-urlencoded. Existing query parameters and the fragment stay as they are.queryParam, default token.
noneNo credential.None.

Details:

  • With an empty token, bearer, header and query send nothing. basic is still sent when a username is set (username: with an empty password); with no username and no token it sends nothing too.
  • A headerName is an RFC 7230 token: letters, digits and ! # $ % & ' * + - . ^ _ ` | ~. The names Host, Content-Length, Content-Type, Connection, Upgrade and Transfer-Encoding, and any name that starts with Sec-WebSocket-, are refused, because the transport sets them.
  • A username is visible ASCII (! to ~) without :. It may be empty.
  • A queryParam is not empty and has only letters, digits and . _ ~ -.
  • Only the settings of the active mode are checked and used. The others are kept so switching modes loses nothing.
  • Over query the 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.

For every scan, the app sends:

POST /api/scans HTTP/1.1
Content-Type: application/json
Authorization: Bearer <token>
User-Agent: nfc-keyboard-emulator/1.1.0

with 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 responseResult in the app
Any 2xx statusSuccess. The response body is ignored.
401 or 403Token rejected. Reported separately from an unreachable server.
Any other status, including 3xx and 5xxError: Server answered with HTTP n.
No answer within 5 seconds, or no connectionError: 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.

  • The app connects to the configured ws:// or wss:// 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. Answer 401 or 403 to 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.
  • 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.
  1. Your server sends scan_request. The app arms: the status bar shows waiting for scan and, if notifications are on, a notification appears.
  2. 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.
  3. Only one request is pending at a time. A new scan_request replaces the old one, which ends with superseded. Repeating the same requestId just restarts the timer.
  4. A request ends with scan_request_ended if it times out, is cancelled, is superseded or is refused (see above).
  5. If Answer scan requests is switched off, the app does not arm and immediately answers with scan_request_ended and reason disabled.

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.

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.

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
}
}
KeyTypeDescription
$schemastringOptional. Ignored by the app.
formatstringRequired. Must be nfc-keyboard-emulator/server-config.
versionintegerRequired. Must be 1. A higher version is rejected with a message asking the user to update the app.
deviceNamestringName sent with every scan, hello and test message. An empty string clears it, which means the computer’s host name.
http.enabledbooleanSwitches HTTP push on or off.
http.urlstringEmpty, or an absolute http:// or https:// URL with a host. The scheme must be lowercase.
http.tokenstringSent 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.authobjectOptional. How the token is sent; see below.
http.payloadobjectOptional. The shape of the scan; see below.
ws.urlstringEmpty, or an absolute ws:// or wss:// URL with a host. The scheme must be lowercase. Shared by stream and request mode.
ws.tokenstringSent according to ws.auth on the upgrade request, by default as Authorization: Bearer <token>. Same characters as http.token.
ws.authobjectOptional. Same as http.auth.
ws.payloadobjectOptional. Same as http.payload. Applies to streamed scans only.
ws.streambooleanSend every scan over the WebSocket.
ws.requestbooleanAnswer 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 have the same shape in http and ws.

KeyTypeDescription
auth.modestringbearer (default), header, basic, query or none. See token transports.
auth.headerNamestringThe header for header mode. Default X-API-Key.
auth.usernamestringThe user name for basic mode. Default empty.
auth.queryParamstringThe parameter for query mode. Default token.
payload.modestringstandard (default) or template.
payload.templatestringThe 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 auth or payload object 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 headerName is fine while auth.mode is bearer, and the template is only checked while payload.mode is template. 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. In basic mode it is the password.
  • Switching a target with a kept token to query counts 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.

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.

The schema for version 1 is published at:

https://docs.noix.dev/nfc-keyboard-emulator/server-config.v1.schema.json

Use it to validate the files you generate.

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,
},
});

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.

Terminal window
cd examples/server
npm install
TOKEN=dev node server.mjs

The 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:

ModeURL
HTTP pushhttp://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.

  • 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 401 or 403; the app reports it as a rejected token and stops reconnecting.
  • Use https:// and wss://. Over http:// and ws:// the token travels in clear text.
  • Prefer a header to a URL parameter. With the query transport 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 Authorization header, in config files or in links. The same goes for access logs that record URLs, if you put a token in a link.
  • Treat uid as 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.