newOS for Developers

Back to Workflows Hub

URL Preview

beginner

Extract metadata from URLs for rich link previews.

Endpoint

GET /post/utils/remote-meta-proxy

Fetches OpenGraph metadata from a remote URL through server proxy.

Request / Response

// Request (query params)
{
  url: string;  // URL to extract metadata from
}

// Response
interface OpenGraphMeta {
  title?: string;       // Page title
  description?: string; // Meta description
  image?: string;       // og:image URL
  siteName?: string;    // og:site_name
  type?: string;        // og:type (article, website, etc.)
  url?: string;         // Canonical URL
}

Implementation

import { newgraphClient } from "newgraph-signals";

// Fetch URL metadata
const targetUrl = "https://example.com/article";
const response = await newgraphClient.api.post.utilsRemoteMetaProxyList({
  url: targetUrl
});

const meta = response.data;

console.log("Title:", meta.title);
console.log("Description:", meta.description);
console.log("Image:", meta.image);

React Hook Pattern

import { useOpenGraph } from "newgraph-signals/hooks";

function LinkPreview({ url }) {
  const { data, loading, error } = useOpenGraph(url);
  
  if (loading) return <div>Loading preview...</div>;
  if (error) return <div>Could not load preview</div>;
  
  return (
    <div className="link-preview">
      {data.image && <img src={data.image} alt="" />}
      <h3>{data.title}</h3>
      <p>{data.description}</p>
      <span>{data.siteName}</span>
    </div>
  );
}

Why Server Proxy?

CORS restrictions — Most websites block direct browser requests

SSR rendering — Server can execute JavaScript to get dynamic OG tags

Caching — Server caches metadata to reduce external requests

Use Cases

Chat links — Show preview cards for shared links
Post embeds — Rich previews for external URLs in posts
URL validation — Verify links are valid before saving

Edge Cases

Missing OG tags — Falls back to title/meta description
Timeout — Will timeout for slow or unresponsive sites
Private URLs — Cannot fetch from authenticated endpoints
Rate limiting — Excessive requests may be throttled