Skip to main content

Client Examples

The repository includes runnable examples beside every bundled client. Start hlquery on port 9200, then run an example from the repository root.

Quick commands

LanguageCommandMore examples
C++cd etc/api/cpp && make && ./basic_usageC++ examples
Gocd etc/api/go && go run ./examples/basic_usageGo examples
Javacd etc/api/java && make exampleJava examples
Node.jscd etc/api/node && npm install && node examples/basic_usage.jsNode.js examples
Pythoncd etc/api/python && python3 examples/basic_usage.pyPython examples
PHPcd etc/api/php && php examples/basic_usage.phpPHP examples
Perlcd etc/api/perl && perl examples/basic_usage.plPerl examples
Rustcd etc/api/rust && cargo run --example basic_usageRust examples
Rubycd etc/api/ruby && ruby example.rbRuby client

The TypeScript package and examples are covered in the TypeScript client guide.

Pick an example by task

Most client folders use the same names:

  • basic_usage checks connectivity and introduces response handling.
  • collections creates, lists, inspects, and removes schemas.
  • documents demonstrates CRUD and imports.
  • search covers query options, filters, sorting, and facets.
  • sql runs SQL-style selection or aggregation.
  • flush demonstrates the administrative flush operation.
  • vector is present in clients with vector helpers.
  • keys is present in clients with API-key management helpers.

Not every SDK implements every example. Use the linked language page as the source of truth for the currently bundled files.

Node.js service example

const Client = require('./lib/Client');

const client = new Client('http://localhost:9200', {
token: process.env.HLQUERY_API_KEY,
auth_method: 'api-key',
timeout: 5000
});

async function findProducts(q) {
const response = await client.search('products', {
q,
query_by: 'title,description',
filter_by: 'in_stock:true',
limit: 10
});

if (!response.isSuccess()) {
throw new Error(response.getError() || 'hlquery search failed');
}
return response.getBody().hits ?? [];
}

Python script example

import os
from lib import Client

client = Client('http://localhost:9200', {
'token': os.environ.get('HLQUERY_API_KEY'),
'auth_method': 'api-key',
})

response = client.search('products', {
'q': 'keyboard',
'query_by': 'title,description',
'filter_by': 'in_stock:true',
'limit': 10,
})

if not response.is_success():
raise RuntimeError(response.get_error())

for hit in response.get_body().get('hits', []):
print(hit['document']['title'])

Raw HTTP remains useful

Client libraries wrap the same HTTP API. When a new server route is not yet available as a typed helper, use the client's low-level request method or a small raw HTTP call, then return to the typed helper after SDK support lands. This is also a useful way to compare an SDK request with a working curl recipe while debugging.