DEV Community

Daniel Igel
Daniel Igel

Posted on

Build link previews without parsing HTML: OG metadata in one API call

Building link unfurl panels — the preview cards you see in Slack, Notion, or iMessage — means fetching the raw page, parsing og: meta tags, falling back to <title> and <meta name="description"> when OG is missing, and resolving relative favicon paths. It's tedious boilerplate that rarely fits cleanly into whatever HTTP client you're already using.

One GET returns OG tags, title, description, canonical URL, and favicon for any URL:

curl --request GET \
  --url 'https://url-metadata-open-graph-api.p.rapidapi.com/api/v1/meta?url=https://github.com' \
  --header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY' \
  --header 'x-rapidapi-host: url-metadata-open-graph-api.p.rapidapi.com'
Enter fullscreen mode Exit fullscreen mode

You get back a normalized object — og.title, og.image, og.description, favicon, canonical — regardless of whether the page has OG tags or falls back to standard meta. The response is cached for 10 minutes, so repeated calls to the same URL skip the origin fetch.

const meta = await fetch(
  `https://url-metadata-open-graph-api.p.rapidapi.com/api/v1/meta?url=${encodeURIComponent(url)}`,
  { headers: { 'x-rapidapi-key': process.env.RAPIDAPI_KEY, 'x-rapidapi-host': 'url-metadata-open-graph-api.p.rapidapi.com' } }
).then(r => r.json());
Enter fullscreen mode Exit fullscreen mode

Need to prefetch multiple links at once? POST /api/v1/meta/batch with { urls: [...] } handles up to 5 URLs concurrently — one round trip instead of five.

Free tier on RapidAPI: https://rapidapi.com/danieligel/api/url-metadata-open-graph-api

When building link previews, do you parse OG tags yourself or reach for a dedicated service?

Top comments (0)