REST-Server Module in KDB-X

This page explains what the REST server is, why you would use it, and how it helps you integrate KDB-X systems with external applications.

What is the REST server?

REST stands for Representational State Transfer. A REST server is the backend system that implements the REST API. In simple terms, the REST server listens for incoming HTTP requests, processes them (for example, by fetching data from a database, applying business logic), and sends responses back to the client.

In KDB-X, the REST server lets you expose a RESTful API interface for your applications. It allows you to map REST operations and URL paths (called endpoints) to q functions (called handlers).

When an HTTP request is received:

  1. The server matches the request's method and path to a registered endpoint.
  2. The associated q function runs.
  3. The result is returned to the client as JSON.

This makes it easy for external systems to call into your KDB-X logic using standard web APIs.

Why use it?

The REST Server makes it easy to integrate KDB-X with the wider ecosystem of applications and services. By exposing q functions through familiar HTTP methods such as GET, POST, PUT, and DELETE, it provides a standard interface that external systems and developers already know how to use. Endpoints can be designed flexibly, supporting path variables, query parameters, headers, and JSON request bodies, which allows you to tailor the API to your specific needs. You remain in control of which functions are exposed and how they behave, giving you both the convenience of RESTful integration and the ability to customize behavior to fit your system.

How it works

At a high level, the workflow is:

  • A client sends an HTTP request (method + path + parameters).
  • The REST server checks for a matching endpoint.
  • The handler function is executed in KDB-X.
  • The response is serialized into JSON and returned to the client.

This approach lets you build RESTful APIs around your existing q code.

Endpoints

A REST server endpoint is a URL that represents a resource in a RESTful API. It serves as the interface through which clients interact with the server to create, read, update, or delete resources. REST endpoints follow specific principles to ensure simplicity, scalability, and consistency.

REST endpoints are structured around resources, which are uniquely identified by Uniform Resource Identifiers (URIs). Each endpoint corresponds to a resource or a collection of resources. For example, /users might represent a collection of users, while /users/123 represents a specific user.

Use cases

The REST server is useful whenever you need to connect KDB-X logic with external systems through a simple, web-based interface. Typical scenarios include:

  • Data retrieval for applications. Expose endpoints that let external dashboards, reporting tools, or web apps fetch query results from KDB-X in real time.
  • Integration with microservices. Allow other services in your ecosystem to call q functions as part of larger workflows.
  • Ingesting external data. Accept incoming data via POST requests (such as trade events, IoT signals, or logs) and process it directly inside KDB-X.
  • Automation and scripting. Enable DevOps teams and analysts to interact with your KDB-X environment programmatically using common HTTP clients like curl, requests, or JavaScript fetch.
  • Custom APIs for clients or partners. Build lightweight REST APIs that expose exactly the information or functionality you want to external parties, without giving them direct database access.

Next steps

Check out the Quickstart guide for more details on how to get started: