Microservice Implementation with Harbour
🔹 Left Side (C-Part in #pragma BEGINDUMP)
This is the low-level HTTP microservice server, written in C using Winsock, embedded in Harbour via #pragma BEGINDUMP.
Key Sections:
HB_FUNC( STARTHTTPSERVER )
– This is the main entry point, triggered by StartHttpServer() from Harbour.
while (1)
– An infinite loop that continuously listens for incoming TCP connections (blocking accept()).
-> ROUTER
– This comment marks the internal routing logic, which checks for request paths like /search.
-> CLIENTSOCKET_RESPONSE
– Here, the server prepares and sends back the HTTP response (usually JSON) to the client.
The orange arrow shows the flow:
StartHttpServer() is called,
a request is received,
routed based on URL,
a response is generated and sent back to the client.
🔹 Right Side (Harbour Code – SearchName() function)
This is the business logic part written in Harbour. It defines what happens when /search?name=... is called.
Step-by-step breakdown:
Variable Setup
cPRGPATH points to the DBF file: "x:\xxhdaten\DATAWIN\KUNDEN.dbf"
a is the array that will hold the search results
USE ... SHARED
– Opens the DBF file with alias "data" in shared mode (multi-user safe)
Loop Through Records
– do while !eof() loops over each record in the DBF
Lines 29–31 (highlighted)
– Extracts the fields: name, ort, plz
– Converts them using my_AnsiToUtf8() to ensure UTF-8 output (important for JSON and web)
AAdd() in Line 34
– Adds each record as an associative array to the result array a
Limit to 20 results
– The loop exits early if more than 20 records are added
Return JSON
– hb_jsonEncode() serializes the result into JSON and returns it to the C-part
🔄 How Both Parts Work Together
A client (e.g. browser or search.php) sends:
GET /search?name=max
The C-based microservice parses the request
Calls Harbour like:
SearchName("max")
The Harbour function:
Opens KUNDEN.dbf
Collects matching records
Returns them as a JSON array
The C-part builds a full HTTP response and sends it back to the client
🧾 What the Client Receives
The client (e.g. a browser or a PHP proxy) receives a response like:
json
Kopieren
Bearbeiten
{
"status": "ok",
"results": [
{ "name": "max", "ort": "Testhausen", "plz": "1234" },
...
]
}
