The Request module provides access to information about the current HTTP request being handled by your server-side code. It includes details such as the request path, method, path parameters, query parameters, headers, body content, and client metadata.
This module is essential for building dynamic behavior based on the request context—such as routing logic, input validation, filtering, and access control.
The Request module is globally available in the platform environment via kd.request. There is no need to import or initialize it manually.
GET, POST, etc.)./users/:id → id).Retrieves a specific path parameter by its index position.
Example
// For URL /users/123/profile
var users = kd.request.getPathParam(0);
// users = "users"
var userId = kd.request.getPathParam(1);
// userId = "123"
var section = kd.request.getPathParam(2);
// section = "profile"
var nonExistent = kd.request.getPathParam(5);
// nonExistent = null
Returns all path parameters as an array.
Example:
// For URL /users/123/profile
const params = kd.request.getPathParams();
// params = ["users", "123", "profile"]
The Kodaris platform will inject data into the current request as needed based on the request type. Use this method to get the value of a data property that was injected.
// For URL /content/about
var isContentPage = kd.request.getProperty("isContentPage");
// isContentPage = true
Retrieves the body/payload of the current HTTP request. For JSON content types, the body is automatically parsed into an object. Returns null if the request has no body or if the body cannot be parsed.
Object | String | null: The request payload or null if none existsconst payload = kd.request.getBody();
// payload = { "email": "john@example.com" }
Retrieves a specific request query parameter.
String | null: The value of the parameter// For URL ?q=searchterm&page=2
const searchQuery = kd.request.getParameter('q');
// searchQuery = "searchterm"
const page = parseInt(kd.request.getParameter('page')) || 1;
// page = 2
const missing = kd.request.getParameter('nonexistent');
// missing = null
Checks if a parameter exists and optionally if it has a specific value.
// For URL ?filter=active&status=published&view=detailed
// Check if filter parameter exists
const hasFilter = kd.request.hasParameter('filter');
// hasFilter = true
// Check if status parameter equals "published"
const isPublished = kd.request.hasParameter('status', 'published');
// isPublished = true
// Check if status parameter equals "draft"
const isDraft = kd.request.hasParameter('status', 'draft');
// isDraft = false
// Check if a non-existent parameter exists
const hasSort = kd.request.hasParameter('sort');
// hasSort = false
Retrieves all request parameters as an object.
// For URL ?limit=20&offset=40&sort=name
const allParams = kd.request.getParameters();
// allParams = { "limit": ["20"], "offset": ["40"], "sort": ["name"] }
Many request urls are natively handled by the Kodaris platform. For example, when a user visits the category page on your website, the platform fetches the requested product category from the database along with its products. Once the data is loaded, the platform will turn the rendering over to the website so you can control how the category and its products are displayed to the user. The platform will provide the EJS template file you should use to render the category page. You can get the EJS template file path the platform wants you to render by calling the getTemplate() method.
// For URL /category/drywall
var template = kd.request.getTemplate();
// template = /src/product/category.ejs
Sets a custom value in the request context for later retrieval.
// Store the start time of processing
kd.request.set('processingStart', Date.now());
// No return value
Sets a custom value in the request context for later retrieval.
// Calculate processing time
var startTime = kd.request.get('processingStart');
// startTime = 1618324567890
// Getting a non-existent value
var noValue = kd.request.get('nonexistent');
// noValue = null
Checks if the there is a current request. For some server-side javascript contexts there is no current request. For example, an automated scheduled task that runs every 5 minutes to send order delivered notifications for any orders that have been recently delivered. Such a scheduled task is initiated by the Kodaris platform and is not initiated by an HTTP request. Thus, there will be now request in the context. You can use the exists() method to see if there is an active request or not before executing request specific logic.
const requestExists = kd.request.exists();
// requestExists = true (in a normal request context)
if (kd.request.exists()) {
// Process the request
} else {
console.log('No active request to process');
}
Checks if the there is a current request. For some server-side javascript contexts there is no current request. For example, an automated scheduled task that runs every 5 minutes to send order delivered notifications for any orders that have been recently delivered. Such a scheduled task is initiated by the Kodaris platform and is not initiated by an HTTP request. Thus, there will be now request in the context. You can use the exists() method to see if there is an active request or not before executing request specific logic.
var path = kd.request.getPath();
// path = "/products/electronics/phones"
// Basic routing
if (path.startsWith('/myapp/dashboard')) {
// Handle myapp requests
} else if (path.startsWith('/promotions/')) {
// Handle promotion requests
}
Checks if the there is a current request. For some server-side javascript contexts there is no current request. For example, an automated scheduled task that runs every 5 minutes to send order delivered notifications for any orders that have been recently delivered. Such a scheduled task is initiated by the Kodaris platform and is not initiated by an HTTP request. Thus, there will be now request in the context. You can use the exists() method to see if there is an active request or not before executing request specific logic.
var url = kd.request.getUrl();
// url = "https://commerce.kodaris.com/content/about