JavaScript (Node/Browser)
const BASE = "https://your-host/api/appointments";
const KEY = process.env.QLYNIC_API_KEY || "your-key";
// GET range with filters
async function listAppointments({ from, to, doctorId, status = "booked,confirmed" }){
const url = new URL(BASE);
if (from) url.searchParams.set("from", from);
if (to) url.searchParams.set("to", to);
if (doctorId) url.searchParams.set("doctorId", String(doctorId));
if (status) url.searchParams.set("status", status);
const res = await fetch(url.toString(), {
headers: { "X-Api-Key": KEY }
});
if (!res.ok) throw new Error("HTTP " + res.status);
return res.json();
}
// POST create
async function createAppointment(payload){
const res = await fetch(BASE, {
method: "POST",
headers: { "Content-Type": "application/json", "X-Api-Key": KEY },
body: JSON.stringify(payload)
});
if (!res.ok) throw new Error("HTTP " + res.status);
return res.json();
}
// POST change status (cancelled only for external clients)
async function setStatus(id, status){
const res = await fetch(`${BASE}/${id}/status`, {
method: "POST",
headers: { "Content-Type": "application/json", "X-Api-Key": KEY },
body: JSON.stringify({ status })
});
if (!res.ok) throw new Error("HTTP " + res.status);
return res.json();
}
C# (HttpClient)
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
var BASE = "https://your-host/api/appointments";
var KEY = Environment.GetEnvironmentVariable("QLYNIC_API_KEY") ?? "your-key";
var http = new HttpClient();
http.DefaultRequestHeaders.Add("X-Api-Key", KEY);
// GET range
async Task<JsonDocument> GetRange(string from, string to, int? doctorId, string status = "booked,confirmed")
{
var url = $"{BASE}?from={from}&to={to}&status={status}" + (doctorId.HasValue ? $"&doctorId={doctorId.Value}" : "");
var res = await http.GetAsync(url);
res.EnsureSuccessStatusCode();
var body = await res.Content.ReadAsStringAsync();
return JsonDocument.Parse(body);
}
// POST create
async Task<JsonDocument> Create(dynamic payload)
{
var json = JsonSerializer.Serialize(payload);
var res = await http.PostAsync(BASE, new StringContent(json, Encoding.UTF8, "application/json"));
res.EnsureSuccessStatusCode();
var body = await res.Content.ReadAsStringAsync();
return JsonDocument.Parse(body);
}
// POST status
async Task<JsonDocument> SetStatus(int id, string status)
{
var json = JsonSerializer.Serialize(new { status });
var res = await http.PostAsync($"{BASE}/{id}/status", new StringContent(json, Encoding.UTF8, "application/json"));
res.EnsureSuccessStatusCode();
var body = await res.Content.ReadAsStringAsync();
return JsonDocument.Parse(body);
}