Skip to content

Search

One endpoint, one parameter. It searches the published posts of the project the credential belongs to, and nothing else.

Last updated

Using it

MethodPathWhat it doesCredential
GET/v1/blog/searchSearch postsKey or session
Examplebash
curl -G 'https://api.cmskite.com/v1/blog/search' \
  -H "authorization: Bearer $KEY" \
  --data-urlencode 'q=port congestion' \
  --data-urlencode 'limit=20'

Results come back in the same shape as a post listing, cursor-paginated like everything else, so the code that renders a listing renders a search result without changes.

What it does and does not do

  • Searches titles, excerpts and bodies.
  • Published content only — always, for every credential. A draft is not findable by searching for it.
  • Handles the punctuation people type. Quotes, apostrophes and stray brackets come back as results rather than as a parse error.
  • Ranks by relevance, then by recency.
  • Scoped to one project, because the credential is.

In a site

A search route that does not leak your keyts
// app/api/search/route.ts -- runs on your server, so the key stays there.
export async function GET(request: Request) {
  const q = new URL(request.url).searchParams.get('q')?.trim()
  if (!q) return Response.json({ data: [] })

  const url = new URL('https://api.cmskite.com/v1/blog/search')
  url.searchParams.set('q', q)
  url.searchParams.set('limit', '20')

  const res = await fetch(url, {
    headers: { authorization: `Bearer ${process.env.CMSKITE_KEY}` },
    // Search results change when content does, not on a timer you pick.
    next: { revalidate: 300 },
  })
  if (!res.ok) return Response.json({ data: [] }, { status: 502 })
  return Response.json(await res.json())
}