Skip to main content
The database mock server is a lightweight Node.js Express application that simulates external database REST APIs for testing and development purposes. It provides sample employee and department data endpoints with support for search filtering and authentication.

Overview

The mock server enables frontend and backend development without requiring access to production databases. It implements realistic API endpoints that match the expected schema for datalink configurations.

Express Server

Simple HTTP server with RESTful endpoints

Sample Data

Pre-populated employee and department records

Search Support

Query parameter filtering for testing search

Authentication

Basic auth simulation for secure endpoints

Server Implementation

The complete mock server is implemented in a single file:
index.js
const express = require('express')
const app = express()
const port = 3005

app.get('/', (req, res) => {
  res.send('Venzia employee db mockup')
})

/**Public endpoint with no auth */
app.get("/api/v1/public/employees/search", (req,res) => {
    const employees = [
        {emp_no:1, first_name:"Adolfo", last_name:"Herrero", hire_date: new Date("2005-10-02")},
        {emp_no:2, first_name:"Lazslo", last_name:"Cravensworth", hire_date: new Date("1960-03-12")},
        {emp_no:3, first_name:"Anastasia", last_name:"Lopez", hire_date: new Date("1999-11-04")},
        {emp_no:4, first_name:"María", last_name:"Martinez", hire_date: new Date("1992-01-02")},
        {emp_no:5, first_name:"Jose", last_name:"Ramirez", hire_date: new Date("2003-03-11")},
        {emp_no:6, first_name:"Mario", last_name:"Gonzalez", hire_date: new Date("2002-02-12")},
        {emp_no:7, first_name:"Eduardo", last_name:"Lopez", hire_date: new Date("2005-01-16")},
        {emp_no:8, first_name:"Ana", last_name:"Cuesta", hire_date: new Date("2002-03-25")},
        {emp_no:9, first_name:"Luisa", last_name:"Rodriguez", hire_date: new Date("2010-02-22")},
        {emp_no:10, first_name:"Marta", last_name:"Boss", hire_date: new Date("2012-04-29")},
        {emp_no:11, first_name:"Elena", last_name:"Torroja", hire_date: new Date("2022-01-02")},
        {emp_no:12, first_name:"Eleazar", last_name:"Fuertes", hire_date: new Date("2023-02-11")},
        {emp_no:13, first_name:"Cristina", last_name:"Juvens", hire_date: new Date("2024-04-14")},
        {emp_no:14, first_name:"Carla", last_name:"Saña", hire_date: new Date("2025-03-22")},
        {emp_no:15, first_name:"Leonor", last_name:"Garcia", hire_date: new Date("2026-03-20")},
        {emp_no:16, first_name:"Jose luis", last_name:"Garcia", hire_date: new Date("2024-12-02")},
        {emp_no:17, first_name:"Rafael", last_name:"Montiel", hire_date: new Date("2003-12-02")},
        {emp_no:18, first_name:"Juan", last_name:"Perez", hire_date: new Date("2006-11-12")},
        {emp_no:19, first_name:"Juana", last_name:"Ruiz", hire_date: new Date("2004-11-06")},
        {emp_no:20, first_name:"Pablo", last_name:"Dolera", hire_date: new Date("2011-02-13")},
    ];
    res.setHeader('Content-Type', 'application/json');
    if(req.query && req.query.query){
        const filteredEmployees = employees.filter(
            emp => emp.first_name.toLowerCase().startsWith(req.query.query)
        );
        res.send(JSON.stringify(filteredEmployees))
    }else{
        res.send(JSON.stringify(employees))
    }
})


/**Endpoint for departments with simulated basic auth */
app.get("/api/v1/private/departments/search", (req,res) => {
    if(!req.headers.authorization){
        res.status(401).json({error:"missing auth header"})
    }
    const EncodedAuth = req.headers.authorization.split(" ")[1];
    const decodedAuth = new Buffer(EncodedAuth, "base64").toString();
    const [user,pass] = decodedAuth.split(":");
    if(user != "user2019" || pass!="g3n3r4l"){
        res.status(401).json({error:"wrong auth "})
    }
    const departments = [
        {dept_no:1, dept_name:"Recursos Humanos"},
        {dept_no:2, dept_name:"Logística"},
        {dept_no:3, dept_name:"Compras"},
        {dept_no:4, dept_name:"Ventas"},
        {dept_no:5, dept_name:"Finanzas"},
        {dept_no:6, dept_name:"Marketing"}
    ];
    res.setHeader('Content-Type', 'application/json');
    if(req.query && req.query.query){
        const filteredDepartments = departments.filter(
            dep => dep.dept_name.toLowerCase().startsWith(req.query.query)
        );
        res.send(JSON.stringify(filteredDepartments));
    }else{
        res.send(JSON.stringify(departments));
    }
})

app.listen(port, () => {
  console.log(`Mock db listening on port ${port}`)
})

API Endpoints

Searches employee records without authentication:
GET http://localhost:3005/api/v1/public/employees/search
Content-Type: application/json
Endpoint Details:
  • URL: /api/v1/public/employees/search
  • Method: GET
  • Authentication: None (public endpoint)
  • Query Parameters:
    • query (optional): Filter by first name (case-insensitive prefix match)
Data Fields:
  • emp_no: Employee number (integer)
  • first_name: Employee first name (string)
  • last_name: Employee last name (string)
  • hire_date: Date of hire (ISO 8601 date)
Searches department records with basic authentication:
GET http://localhost:3005/api/v1/private/departments/search
Authorization: Basic dXNlcjIwMTk6ZzNuM3I0bA==
Content-Type: application/json
Endpoint Details:
  • URL: /api/v1/private/departments/search
  • Method: GET
  • Authentication: Basic Auth (required)
  • Credentials:
    • Username: user2019
    • Password: g3n3r4l
  • Query Parameters:
    • query (optional): Filter by department name (case-insensitive prefix match)
Data Fields:
  • dept_no: Department number (integer)
  • dept_name: Department name (string)
The basic auth header dXNlcjIwMTk6ZzNuM3I0bA== decodes to user2019:g3n3r4l.

Sample Data

Employee Records

The mock server provides 20 employee records:
[
  {"emp_no":1, "first_name":"Adolfo", "last_name":"Herrero", "hire_date":"2005-10-02"},
  {"emp_no":2, "first_name":"Lazslo", "last_name":"Cravensworth", "hire_date":"1960-03-12"},
  {"emp_no":3, "first_name":"Anastasia", "last_name":"Lopez", "hire_date":"1999-11-04"},
  {"emp_no":4, "first_name":"María", "last_name":"Martinez", "hire_date":"1992-01-02"},
  {"emp_no":5, "first_name":"Jose", "last_name":"Ramirez", "hire_date":"2003-03-11"},
  ...
]

Department Records

The mock server provides 6 department records:
[
  {"dept_no":1, "dept_name":"Recursos Humanos"},
  {"dept_no":2, "dept_name":"Logística"},
  {"dept_no":3, "dept_name":"Compras"},
  {"dept_no":4, "dept_name":"Ventas"},
  {"dept_no":5, "dept_name":"Finanzas"},
  {"dept_no":6, "dept_name":"Marketing"}
]

Setup and Installation

1

Install Dependencies

Navigate to the db mock directory and install Express:
cd "db mock"
npm install express
2

Start the Server

Run the mock server:
node index.js
You should see:
Mock db listening on port 3005
3

Verify Server

Open your browser or use curl:
curl http://localhost:3005
Expected response:
Venzia employee db mockup
4

Test Endpoints

Test the employee search endpoint:
curl http://localhost:3005/api/v1/public/employees/search?query=ana

Configuration

Port Configuration

The server runs on port 3005 by default. To change the port:
const port = 3005  // Change this value
Or use an environment variable:
const port = process.env.PORT || 3005

Adding Custom Data

To add more employee records:
const employees = [
    // ... existing employees
    {emp_no:21, first_name:"Your Name", last_name:"LastName", hire_date: new Date("2026-01-01")},
];

CORS Configuration

For cross-origin requests from the frontend, add CORS middleware:
const cors = require('cors');
app.use(cors());

Authentication Simulation

The department endpoint simulates HTTP Basic Authentication:
if(!req.headers.authorization){
    res.status(401).json({error:"missing auth header"})
}
const EncodedAuth = req.headers.authorization.split(" ")[1];
const decodedAuth = new Buffer(EncodedAuth, "base64").toString();
const [user,pass] = decodedAuth.split(":");
if(user != "user2019" || pass!="g3n3r4l"){
    res.status(401).json({error:"wrong auth"})
}
To use the mock server with Venzia Datalinks:
datalink-employees.json
{
  "name": "employee-search",
  "label": "Employee Search",
  "endpoint": "http://localhost:3005/api/v1/public/employees/search",
  "method": "GET",
  "fields": [
    {
      "name": "emp_no",
      "label": "Employee Number",
      "type": "number"
    },
    {
      "name": "first_name",
      "label": "First Name",
      "type": "string"
    },
    {
      "name": "last_name",
      "label": "Last Name",
      "type": "string"
    },
    {
      "name": "hire_date",
      "label": "Hire Date",
      "type": "date"
    }
  ],
  "searchable": true,
  "searchField": "query"
}
datalink-departments.json
{
  "name": "department-search",
  "label": "Department Search",
  "endpoint": "http://localhost:3005/api/v1/private/departments/search",
  "method": "GET",
  "authentication": {
    "type": "basic",
    "username": "user2019",
    "password": "g3n3r4l"
  },
  "fields": [
    {
      "name": "dept_no",
      "label": "Department Number",
      "type": "number"
    },
    {
      "name": "dept_name",
      "label": "Department Name",
      "type": "string"
    }
  ],
  "searchable": true,
  "searchField": "query"
}

3. Place Configuration Files

Copy the JSON files to the Alfresco module:
cp datalink-*.json \
  venzia-datalink/src/main/resources/alfresco/extension/datalink/
The backend module’s RegisterDataLink component automatically loads all files matching the datalink-*.json pattern.

Development Workflow

1

Start Mock Server

node index.js
2

Start Alfresco

Deploy the backend module with datalink configurations
3

Start Content App

Launch the Angular frontend with the datalink extension
4

Test Integration

Open a document and test datalink search functionality

Testing Examples

Using cURL

curl http://localhost:3005/api/v1/public/employees/search

Using JavaScript Fetch

// Public endpoint
fetch('http://localhost:3005/api/v1/public/employees/search?query=ana')
  .then(res => res.json())
  .then(data => console.log(data));

// Private endpoint with basic auth
const credentials = btoa('user2019:g3n3r4l');
fetch('http://localhost:3005/api/v1/private/departments/search', {
  headers: {
    'Authorization': `Basic ${credentials}`
  }
})
  .then(res => res.json())
  .then(data => console.log(data));

Production Considerations

This mock server is intended for development and testing only. Do not use in production environments.

Limitations

  • No persistence - data resets on server restart
  • Basic authentication is simulated (not secure)
  • No database connection
  • Limited error handling
  • No request validation
  • No rate limiting

For Production

Replace the mock server with:
  • Real database connections (PostgreSQL, MySQL, etc.)
  • Proper authentication (OAuth, JWT, etc.)
  • Request validation and sanitization
  • Error handling and logging
  • API rate limiting
  • HTTPS/TLS encryption

Next Steps

Backend Module

Learn how the backend consumes these APIs

Frontend Extension

See how the UI displays datalink search results

Build docs developers (and LLMs) love