Code examples

Complete programs you can run as they are. Each one reads your key from FENGSHUI_API_KEY, fetches a Kua number with its favourable directions and a love compatibility score, prints RFC 9457 errors clearly and waits for Retry-After when the quota is used up.

File examples/curl/kua.sh · run with FENGSHUI_API_KEY=fsk_… sh kua.sh

#!/bin/sh
# Kua number and love compatibility with the Feng Shui API.
# Usage: FENGSHUI_API_KEY=fsk_... sh kua.sh    (optional: FENGSHUI_API_URL, pipe through `jq` for pretty output)
set -eu

: "${FENGSHUI_API_KEY:?Set FENGSHUI_API_KEY to your API key}"
BASE="${FENGSHUI_API_URL:-https://fengshui-api.com}/api/v2"

# --retry waits for Retry-After on 429; --fail-with-body prints the RFC 9457 error and exits non-zero.
api() {
  path="$1"; shift
  curl --silent --show-error --fail-with-body --retry 3 \
    --header "X-API-Key: $FENGSHUI_API_KEY" \
    --get "$BASE$path" "$@"
  echo
}

echo "Kua number:"
api /feng-shui/kua --data-urlencode "date=1985-03-15" --data-urlencode "gender=female"

echo "Love compatibility:"
api /compatibility/love --data-urlencode "date1=1990-06-15" --data-urlencode "date2=1992-03-10"

Expected output

Kua 9 — East group (Li)
Favourable directions:
  E   Sheng Qi  Success, wealth and vitality — the best direction
  SE  Tian Yi   Health, healing and helpful people
  N   Yan Nian  Longevity, harmony and good relationships
  S   Fu Wei    Stability, clarity and personal growth
Love compatibility Horse & Monkey: 3/4 (good)

Postman, Insomnia, Bruno

No collection to maintain: import openapi.yaml (or openapi.json) — every endpoint, parameter and example appears as a ready request. Set the X-API-Key header once in the collection's authorisation settings.

Generate a typed client

The OpenAPI 3.1 contract works with standard generators, for example:

# TypeScript types
npx openapi-typescript https://fengshui-api.com/openapi.yaml -o fengshui-api.d.ts

# A client in almost any language (Java, Kotlin, C#, Go, Python, Swift…)
docker run --rm -v "$PWD:/out" openapitools/openapi-generator-cli generate \
  -i https://fengshui-api.com/openapi.yaml -g python -o /out/fengshui-client

Tips for production

  • Keep the key on your server. Browser code would expose it to everyone; call the API from your backend and cache the results — they never change for the same input.
  • Send the key in the X-API-Key header (or Authorization: Bearer), never in the URL.
  • Watch the RateLimit header (r= remaining requests) and back off on 429 using Retry-After.
  • Show errors[].message from 422 responses directly to users — they are written for people.

Per-endpoint parameters and responses: API reference. No key yet? Create a free account.