embed
Type: <string>
It returns the specified data field as response over the target url, mimicking the same headers and body of the original resource.
The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://news.ycombinator.com/item?id=13713480' URL with 'screenshot' & 'embed' API parameters:
CLI Microlink API example
microlink https://news.ycombinator.com/item?id=13713480&screenshot&embed=screenshot.urlcURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://news.ycombinator.com/item?id=13713480" \
-d "screenshot=true" \
-d "embed=screenshot.url"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://news.ycombinator.com/item?id=13713480', {
screenshot: true,
embed: "screenshot.url"
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://news.ycombinator.com/item?id=13713480",
"screenshot": "true",
"embed": "screenshot.url"
}
response = requests.get(url, params=querystring)
print(response.json())Ruby Microlink API example
require 'uri'
require 'net/http'
base_url = "https://api.microlink.io/"
params = {
url: "https://news.ycombinator.com/item?id=13713480",
screenshot: "true",
embed: "screenshot.url"
}
uri = URI(base_url)
uri.query = URI.encode_www_form(params)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
response = http.request(request)
puts response.bodyPHP Microlink API example
<?php
$baseUrl = "https://api.microlink.io/";
$params = [
"url" => "https://news.ycombinator.com/item?id=13713480",
"screenshot" => "true",
"embed" => "screenshot.url"
];
$query = http_build_query($params);
$url = $baseUrl . '?' . $query;
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET"
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #: " . $err;
} else {
echo $response;
}Golang Microlink API example
package main
import (
"fmt"
"net/http"
"net/url"
"io"
)
func main() {
baseURL := "https://api.microlink.io"
u, err := url.Parse(baseURL)
if err != nil {
panic(err)
}
q := u.Query()
q.Set("url", "https://news.ycombinator.com/item?id=13713480")
q.Set("screenshot", "true")
q.Set("embed", "screenshot.url")
u.RawQuery = q.Encode()
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
panic(err)
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body))
}import mql from '@microlink/mql'
const { data } = await mql('https://news.ycombinator.com/item?id=13713480', {
screenshot: true,
embed: "screenshot.url"
})You can use dot notation to reference a nested data field of the response payload.
Why use embed
The embed parameter transforms Microlink API from a JSON endpoint into a direct asset server. Instead of receiving JSON and parsing it with JavaScript, you get the actual resource (image, PDF, etc.) that can be used directly in:
- HTML
<img>tags - CSS
background-imageproperties - Markdown image syntax
- Open Graph meta tags
HTML integration
Embed screenshots directly in your HTML markup:
<img
src="https://api.microlink.io/?url=https%3A%2F%2Fnews.ycombinator.com%2Fitem%3Fid%3D13713480&meta=false&screenshot=&embed=screenshot.url"
alt="Hacker News"
>And it will be rendered as an external image:
CSS integration
Use embedded URLs directly in stylesheets:
.hero-background {
background-image: url(/images/image-1.png);
background-size: cover;
}Markdown integration
Embed in any Markdown document:
Common embed fields
| Field | Description | Use case |
|---|---|---|
screenshot.url | Screenshot image URL | Social cards, previews |
pdf.url | Generated PDF URL | Document downloads |
image.url | Primary image URL | Link previews |
logo.url | Website logo URL | Brand displays |
video.url | Video source URL | Media embeds |
Combining with other parameters
Embed works well with other parameters for customized output:
The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://microlink.io' URL with 'screenshot', 'device' & 'embed' API parameters:
CLI Microlink API example
microlink https://microlink.io&screenshot&device='iPhone X'&embed=screenshot.urlcURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://microlink.io" \
-d "screenshot=true" \
-d "device=iPhone%20X" \
-d "embed=screenshot.url"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://microlink.io', {
screenshot: true,
device: "iPhone X",
embed: "screenshot.url"
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://microlink.io",
"screenshot": "true",
"device": "iPhone X",
"embed": "screenshot.url"
}
response = requests.get(url, params=querystring)
print(response.json())Ruby Microlink API example
require 'uri'
require 'net/http'
base_url = "https://api.microlink.io/"
params = {
url: "https://microlink.io",
screenshot: "true",
device: "iPhone X",
embed: "screenshot.url"
}
uri = URI(base_url)
uri.query = URI.encode_www_form(params)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
response = http.request(request)
puts response.bodyPHP Microlink API example
<?php
$baseUrl = "https://api.microlink.io/";
$params = [
"url" => "https://microlink.io",
"screenshot" => "true",
"device" => "iPhone X",
"embed" => "screenshot.url"
];
$query = http_build_query($params);
$url = $baseUrl . '?' . $query;
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET"
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #: " . $err;
} else {
echo $response;
}Golang Microlink API example
package main
import (
"fmt"
"net/http"
"net/url"
"io"
)
func main() {
baseURL := "https://api.microlink.io"
u, err := url.Parse(baseURL)
if err != nil {
panic(err)
}
q := u.Query()
q.Set("url", "https://microlink.io")
q.Set("screenshot", "true")
q.Set("device", "iPhone X")
q.Set("embed", "screenshot.url")
u.RawQuery = q.Encode()
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
panic(err)
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body))
}import mql from '@microlink/mql'
const { data } = await mql('https://microlink.io', {
screenshot: true,
device: "iPhone X",
embed: "screenshot.url"
})Generate and embed a mobile screenshot directly.
Open Graph images
A common use case is generating dynamic Open Graph images:
<meta property="og:image" content="https://api.microlink.io/?url=https://your-site.com/blog/post&screenshot=true&meta=false&embed=screenshot.url">Security considerations
To authenticate requests securely when using embed in client-side code, use
proxy
and edge-proxy
to protect your API credentials.Read more about that at the authentication section.