> Documentation index: https://www.socialcrawl.dev/llms.txt > Every page is also available as Markdown by adding .md. # Hono (/docs/quickstart/hono) Build a Hono app that reads a profile, searches many platforms and pages through posts, on any runtime The app serves three routes under `/api`, and each answers with the API's JSON unchanged. ## Prerequisites - Node.js 22.18 or later, which runs TypeScript as it is. - Hono 4. - A SocialCrawl API key. Keys start with `sc_`. Get a free API key at https://www.socialcrawl.dev/dashboard/api. New accounts start with 100 welcome credits and no card is needed. ## Set up Install Hono and its Node server, then set your key. ```bash title="Terminal" npm install hono @hono/node-server export SOCIALCRAWL_API_KEY=sc_your_key_here ``` Keep the key on the server, out of your code and out of the browser. ## Get a profile The helper sends your key in the `x-api-key` header and answers with the API's JSON and status. ```typescript title="src/index.ts" import { Hono } from "hono"; import { env } from "hono/adapter"; import type { Context } from "hono"; const API = "https://www.socialcrawl.dev"; const app = new Hono(); // Send one request with your key and answer with the API's JSON and status. // env(c) reads the key the same way on Node, Bun, Deno and Workers. async function socialcrawl(c: Context, path: string, params: Record) { const { SOCIALCRAWL_API_KEY } = env<{ SOCIALCRAWL_API_KEY: string }>(c); const res = await fetch(`${API}${path}?${new URLSearchParams(params)}`, { headers: { "x-api-key": SOCIALCRAWL_API_KEY }, }); return Response.json(await res.json(), { status: res.status }); } app.get("/api/profile", (c) => socialcrawl(c, "/v1/tiktok/profile", { handle: c.req.query("handle") ?? "charlidamelio" }), ); ``` Every answer carries `success`. Branch on it, then on `error.type`, never on the message text. ## Search across platforms With `dry_run=1` the search is free and runs nothing. `data.estimate` holds the credits and seconds the real search would take. ```typescript title="src/index.ts" // dry_run=1 prices the search and runs nothing. app.get("/api/search", (c) => socialcrawl(c, "/v1/search/everywhere", { query: c.req.query("query") ?? "oat milk", format: "compact", dry_run: "1", }), ); ``` Drop `dry_run` to run the search for 20 credits. ## Get posts and the next page Each answer holds one page of posts in `data.items`. Send `pagination.next_cursor` back as `cursor`, and stop when `pagination.has_more` is false. ```typescript title="src/index.ts" // Send the last answer's pagination.next_cursor back as ?cursor=. app.get("/api/posts", (c) => { const params: Record = { handle: c.req.query("handle") ?? "charlidamelio" }; const cursor = c.req.query("cursor"); if (cursor) params.cursor = cursor; return socialcrawl(c, "/v1/tiktok/profile/videos", params); }); export default app; ``` A page of posts costs 1 credit. ## Deploy anywhere `src/index.ts` never touches the runtime, so only the entry point changes. Bun runs it as it is with `bun run src/index.ts`, Deno with `Deno.serve(app.fetch)`, and Cloudflare Workers with `main` set to it in `wrangler.jsonc`. On Node, `src/server.ts` starts it: ```typescript title="src/server.ts" import { serve } from "@hono/node-server"; import app from "./index.ts"; serve({ fetch: app.fetch, port: Number(process.env.PORT ?? 3000) }); ``` ## Test it Start the app with `node src/server.ts`, then call the three routes. The answers hold `data.author.followers`, `data.estimate` and `pagination.next_cursor`. ```bash title="Terminal" curl "http://localhost:3000/api/profile?handle=charlidamelio" curl "http://localhost:3000/api/search?query=oat+milk" curl "http://localhost:3000/api/posts?handle=charlidamelio&cursor=" ``` ## Next steps - [Price a watch for free](/docs/engines/monitors.md): POST /v1/monitors?dry_run=1 quotes a scheduled watch of an account and creates nothing. - [Common jobs](/docs/common-jobs.md): The first call for each job, from profiles to comments and reviews. - [Search](/docs/search.md): Choose between one platform - [Errors](/docs/errors.md): Every error type, what it means, and which ones to retry.