Skip to content

Using oEmbed With Unknown Providers

Will Strohl edited this page Nov 19, 2026 · 2 revisions

Using oEmbed discovery for unknown providers

Use Wrapper.GetContent for a URL that is not automatically routed to a known provider. The wrapper first checks explicit provider routing; if no active pattern matches, it performs standards-based unauthenticated JSON discovery.

using WillStrohl.API.oEmbed;

var request = new RequestInfo("https://example.com/article/123", 800, 600);
var output = new Wrapper().GetContent(request);

Discovery sources

The resource response may advertise an oEmbed endpoint in either location:

HTML link metadata

<link rel="alternate"
      type="application/json+oembed"
      href="/oembed?resource=article-123" />

The rel value must include alternate, the type must be application/json+oembed, and the href must resolve to an HTTP or HTTPS URL. Relative endpoints are resolved against the resource URL.

HTTP Link header

Link: </oembed?resource=article-123>; rel="alternate"; type="application/json+oembed"

The implementation accepts the same JSON oEmbed type from HTTP Link metadata. HTML metadata is examined before response headers.

Discovery request

The discovered endpoint is called with JSON oEmbed parameters:

  • url: the original resource URL, URL-encoded.
  • format=json.
  • maxwidth: included when RequestInfo.MaxWidth is greater than -1.
  • maxheight: included when RequestInfo.MaxHeight is greater than -1.

Existing endpoint query parameters are preserved. URL fragments are removed from the endpoint request.

Supported response types

Discovery parses standard JSON responses into the existing response models:

  • photo
  • video
  • rich
  • link

For a discovered link response, Wrapper.GetContent returns the response title. Video and rich responses pass through the same safe HTML transformation used by known providers.

XML discovery, authenticated discovery, and proprietary provider metadata are intentionally unsupported.

Failure behavior

Discovery returns an unsupported-provider error when:

  • The resource URL is not absolute HTTP/HTTPS.
  • No valid JSON oEmbed link is advertised.
  • The discovered endpoint is not HTTP/HTTPS.
  • The response is malformed JSON.
  • The response type is unsupported.
  • The security policy blocks the resource, endpoint, DNS result, or redirect.

Applications should treat provider failures as expected remote-service failures and provide an appropriate fallback UI.

Local discovery testing

The repository’s tests use local or mock responses rather than live provider calls. Follow the project’s MSBuild and test instructions in Development and release.