### Golang Microlink API example Source: https://microlink.io/docs/api/parameters/insights/lighthouse Golang example that builds a URL with the insights.lighthouse.output parameter set to html and performs a GET request. ```go 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://css-tricks.com/nerds-guide-color-web") q.Set("insights.lighthouse.output", "html") 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)) } ``` -------------------------------- ### Golang filter example Source: https://microlink.io/docs/guides/embed/caching-and-performance Golang example using `net/http` to send a GET request with the `filter` parameter. ```go 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://stripe.com") q.Set("filter", "title,description,image.url,logo.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)) } ``` -------------------------------- ### Golang Microlink API example Source: https://microlink.io/docs/api/parameters/screenshot/overlay Golang example using the standard library to call the Microlink API. It constructs a GET request with the 'screenshot.overlay' parameters and prints the response body. ```go 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://www.apple.com/music") q.Set("screenshot.overlay.background", "linear-gradient(225deg, #FF057C 0%, #8D0B93 50%, #321575 100%)") q.Set("screenshot.overlay.browser", "dark") 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)) } ``` -------------------------------- ### Golang Microlink API example with meta=false Source: https://microlink.io/docs/api/parameters/meta Golang example using the standard library to call the Microlink API with `meta=false`. It constructs the URL with `url.Parse` and `q.Set`, sends a GET request, and prints the response body. ```go 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://www.youtube.com/watch?v=9P6rdqiybaw") q.Set("meta", "false") 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)) } ``` -------------------------------- ### Golang: net/http GET with meta=false Source: https://microlink.io/docs/guides/common/production-patterns.md Golang example using net/http to send a GET request to the Microlink API with url, screenshot, and meta parameters. It builds the query string with url.Values and prints the response body. ```go 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://example.com") q.Set("screenshot", "true") q.Set("meta", "false") 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)) } ``` -------------------------------- ### Golang Microlink API example with proxy.url Source: https://microlink.io/docs/api/parameters/proxy Golang example for the Microlink API using the proxy.url parameter. It builds a GET request with the URL and proxy parameters, sends it, and prints the response body. ```go 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://geolocation.microlink.io") q.Set("proxy.url", "https://myproxy:603f60f5@superproxy.cool:8001") 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)) } ``` -------------------------------- ### Golang example with proxy.location Source: https://microlink.io/docs/api/parameters/proxy Use Go to send a GET request with the proxy.location parameter set to 'us'. ```go 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://geolocation.microlink.io") q.Set("proxy.location", "us") 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)) } ``` -------------------------------- ### Initialize client and search Source: https://microlink.io/docs/sdk/methods/search Initializes the Microlink client with an API key and performs a search query. The resolved page contains a `results` array; each item's shape depends on the `type` parameter. This example is the base client used by all other examples on the page. ```javascript const microlink = createClient({ apiKey: process.env.MICROLINK_API_KEY }) const page = await microlink.search('Lotus Elise S2') console.log(page.results) ``` -------------------------------- ### Search with options example Source: https://microlink.io/docs/sdk/methods/search Example of a search request using the 'news' vertical with period, location, and limit options. The response is assigned to results. ```javascript const { results } = await microlink.search('open source llm', { type: 'news', period: 'week', location: 'us', limit: 10 }) ``` -------------------------------- ### Search maps with type: 'maps' Source: https://microlink.io/docs/sdk/methods/search Use `type: 'maps'` to get richer place data including opening hours, price levels, place types, and thumbnails. The example shows a search for restaurants in Madrid and the structure of the first result. ```javascript const { results } = await microlink.search('restaurants madrid', { type: 'maps' }) results[0] // { // title: 'Rosi La Loca', // address: 'C. de Cádiz, 4, Centro, 28012 Madrid, Spain', // latitude: 40.4158037, // longitude: -3.7029837, // rating: 4.7, // ratingCount: 25007, // type: 'Restaurant', // types: ['Restaurant', 'Lounge bar'], // price: { level: '€20–40' }, // phone: { number: '+34 915 32 66 81' }, // opening: { hours: { Monday: '12:30 PM–1:30 AM', … } }, // url: 'http://www.rosilaloca.com/', // place: { id: 'ChIJgwIBTHkoQg0RD1lm5kc2tWI' }, // cid: '7112650868937611535' // } ``` -------------------------------- ### Call the Microlink API with the SDK Source: https://microlink.io/docs/guides/embed Canonical shape for every example in this guide. Each capability is a method; for example, microlink.embed(url) is the same call as ?url=…&iframe=true. Works as a plain HTTPS GET to https://api.microlink.io if you call the API directly. ```javascript import createClient from 'microlink.io' const microlink = createClient() const { title, description, image } = await microlink.metadata( 'https://example.com' ) ``` -------------------------------- ### CLI Microlink API example with palette Source: https://microlink.io/docs/guides/embed/metadata-api CLI example for the palette API parameter. ```bash microlink https://stripe.com&palette ``` -------------------------------- ### Pagination: next() to get the following page Source: https://microlink.io/docs/sdk/methods/search Every page exposes next(), which resolves to the following page of the same query with the same options. ```javascript const first = await microlink.search('node.js frameworks') const second = await first.next() ``` -------------------------------- ### Search shopping products with type: 'shopping' Source: https://microlink.io/docs/sdk/methods/search Pass `type: 'shopping'` to `microlink.search` to retrieve product listings. The example shows the first result's structure, including parsed price and rating fields. ```javascript const { results } = await microlink.search('macbook pro', { type: 'shopping' }) results[0] // { // title: '14-inch MacBook Pro Apple M5 chip CPU and GPU', // url: 'https://www.google.com/search?ibp=oshop&q=macbook+pro&prds=…', // publisher: 'Apple', // price: { symbol: '$', amount: 1699 }, // rating: { score: 4.8, total: 5, reviews: 2400 }, // id: '1293272249390991376' // } ``` -------------------------------- ### Create client and fetch metadata Source: https://microlink.io/docs/sdk/getting-started/overview Create a client and call the metadata product to fetch unified metadata from a URL. ```javascript import createClient from 'microlink.io' const microlink = createClient() const { title, description } = await microlink.metadata('https://vercel.com') ``` -------------------------------- ### Search scholar papers with type: 'scholar' Source: https://microlink.io/docs/sdk/methods/search Pass `type: 'scholar'` to `microlink.search` to retrieve academic papers. The example shows the first result's structure, including citation count and PDF link. ```javascript const { results } = await microlink.search('attention is all you need', { type: 'scholar' }) results[0] // { // title: 'Attention is all you need', // url: 'https://proceedings.neurips.cc/paper/2017/hash/3f5ee243547dee91fbd053c1c4a845aa-Abstract.html', // description: '…to attend to all positions in the decoder…', // publisher: 'A Vaswani, N Shazeer, N Parmar… - Advances in neural …, 2017', // year: 2017, // citations: 249883, // pdf: { url: 'https://proceedings.neurips.cc/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf' }, // id: '5Gohgn6QFikJ' // } ``` -------------------------------- ### Filter shopping results by price.amount Source: https://microlink.io/docs/sdk/methods/search The `price.amount` field is already a number, so you can filter results without parsing currency strings. This example filters for products under $500. ```javascript const affordable = results.filter(r => r.price.amount < 500) ``` -------------------------------- ### PHP filter example Source: https://microlink.io/docs/guides/embed/caching-and-performance PHP example using cURL to send a GET request with the `filter` parameter. ```php "https://stripe.com", "filter" => "title,description,image.url,logo.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 example: function with scripts Source: https://microlink.io/docs/api/parameters/function Builds a URL with query parameters and sends a GET request using net/http. ```go 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) } fn := `({ page }) => page.evaluate("jQuery.fn.jquery")` q := u.Query() q.Set("url", "https://microlink.io") q.Set("function", fn) q.Set("scripts", "https://code.jquery.com/jquery-3.5.0.min.js") 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)) } ``` -------------------------------- ### Ruby filter example Source: https://microlink.io/docs/guides/embed/caching-and-performance Ruby example using `net/http` to send a GET request with the `filter` parameter. ```ruby require 'uri' require 'net/http' base_url = "https://api.microlink.io/" params = { url: "https://stripe.com", filter: "title,description,image.url,logo.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.body ``` -------------------------------- ### CLI screenshot example Source: https://microlink.io/docs/guides/embed/caching-and-performance CLI example using `screenshot` and `embed` parameters to return a screenshot directly. ```bash microlink https://stripe.com&screenshot&embed=screenshot.url ``` -------------------------------- ### Get page insights with microlink_insights Source: https://microlink.io/docs/api/getting-started/mcp Example payload for microlink_insights to get Lighthouse performance insights and technology detection. ```json { "tool": "microlink_insights", "arguments": { "url": "https://microlink.io", "insights": { "lighthouse": { "preset": "perf" }, "technologies": true } } } ``` -------------------------------- ### Use microlink subcommands Source: https://microlink.io/docs/api/getting-started/cli Shows example CLI invocations for unified metadata, markdown, screenshot, logo, and search subcommands. Pass a URL with no product to get unified metadata. ```bash microlink https://example.com microlink markdown https://example.com microlink screenshot https://example.com --fullPage microlink logo https://github.com --square microlink search "best coffee" --limit 10 --location es ``` -------------------------------- ### PHP Microlink API example Source: https://microlink.io/docs/api/parameters/insights/lighthouse PHP example using cURL to GET the Microlink API with the insights.lighthouse.onlyCategories parameter. ```php "https://css-tricks.com/nerds-guide-color-web", "insights.lighthouse.onlyCategories" => "accessibility" ]; $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 with palette Source: https://microlink.io/docs/guides/embed/metadata-api Golang example for the palette API parameter. ```go 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://stripe.com") q.Set("palette", "true") 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)) } ``` -------------------------------- ### Ruby Microlink API example Source: https://microlink.io/docs/api/parameters/insights/lighthouse Ruby example using Net::HTTP to send a GET request with the insights.lighthouse.onlyCategories parameter. ```ruby require 'uri' require 'net/http' base_url = "https://api.microlink.io/" params = { url: "https://css-tricks.com/nerds-guide-color-web", insights.lighthouse.onlyCategories: "accessibility" } 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.body ``` -------------------------------- ### CLI example: function with require Source: https://microlink.io/docs/api/parameters/function Runs a function that uses require() to load cheerio and returns text from an HTML string. ```bash microlink https://example.com&function='() => { const cheerio = require('"'"'cheerio'"'"') const $ = cheerio.load('"'"'

Hello world

'"'"') return $('"'"'h1'"'"').text() }' ``` -------------------------------- ### Python Microlink API example Source: https://microlink.io/docs/api/parameters/insights/lighthouse Python example using the requests library to GET the Microlink API with the insights.lighthouse.onlyCategories parameter. ```python import requests url = "https://api.microlink.io/" querystring = { "url": "https://css-tricks.com/nerds-guide-color-web", "insights.lighthouse.onlyCategories": "accessibility" } response = requests.get(url, params=querystring) print(response.json()) ``` -------------------------------- ### Golang Microlink API example Source: https://microlink.io/docs/api/parameters/waitForSelector Shows how to use Go to call the Microlink API with waitForSelector=main. ```go 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://dev.to") q.Set("screenshot", "true") q.Set("waitForSelector", "main") 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)) } ``` -------------------------------- ### Python Microlink API example Source: https://microlink.io/docs/guides/embed/custom-previews-with-ai Use Python requests to fetch metadata. The example sends a GET request with the URL parameter and prints the JSON response. ```python import requests url = "https://api.microlink.io/" querystring = { "url": "https://stripe.com" } response = requests.get(url, params=querystring) print(response.json()) ``` -------------------------------- ### cURL Microlink API example Source: https://microlink.io/docs/guides/content-conversion/url-to-markdown Sends a GET request to the Microlink API with query parameters for URL, selector, attribute, meta, and embed to get markdown output. ```bash curl -G "https://api.microlink.io" \ -d "url=https://microlink.io/docs/api/getting-started/overview" \ -d "data.markdown.selector=main" \ -d "data.markdown.attr=markdown" \ -d "meta=false" \ -d "embed=markdown" ``` -------------------------------- ### CLI example with proxy.url Source: https://microlink.io/docs/api/parameters/proxy Use the CLI to request a proxy with a custom proxy URL. The proxy.url parameter is set to the provided proxy server. ```bash microlink https://geolocation.microlink.io&proxy.url=https://myproxy:603f60f5@superproxy.cool:8001 ``` -------------------------------- ### cURL: GET request with screenshot.fullPage Source: https://microlink.io/docs/api/parameters/screenshot/fullPage Use cURL to send a GET request to the Microlink API with the `screenshot.fullPage` parameter set to true. The example targets 'https://microlink.io/recipes'. ```bash curl -G "https://api.microlink.io" \ -d "url=https://microlink.io/recipes" \ -d "screenshot.fullPage=true" ``` -------------------------------- ### CLI Microlink API example Source: https://microlink.io/docs/api/parameters/waitForSelector Shows how to use the Microlink CLI to take a screenshot with waitForSelector=main. ```bash microlink https://dev.to&screenshot&waitForSelector=main ``` -------------------------------- ### cURL Microlink API example Source: https://microlink.io/docs/guides/pdf/embedding cURL example for the Microlink API with pdf.format, pdf.margin, meta, and embed parameters. Uses -G to send GET request with data. ```bash curl -G "https://api.microlink.io" \ -d "url=https://rauchg.com/2014/7-principles-of-rich-web-applications" \ -d "pdf.format=Letter" \ -d "pdf.margin=1cm" \ -d "meta=false" \ -d "embed=pdf.url" ``` -------------------------------- ### Golang: Request Lighthouse report with desktop preset Source: https://microlink.io/docs/guides/insights/lighthouse-reports Use Go's net/http to call the Microlink API with the desktop Lighthouse preset. The response body is printed. ```go 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://vercel.com") q.Set("insights.technologies", "false") q.Set("insights.lighthouse.preset", "desktop") q.Set("meta", "false") 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)) } ``` -------------------------------- ### cURL Microlink API example Source: https://microlink.io/docs/guides/embed Use cURL to send a GET request to the Microlink API with the URL as a query parameter. The example targets 'https://www.youtube.com/watch?v=9P6rdqiybaw'. ```bash curl -G "https://api.microlink.io" \ -d "url=https://www.youtube.com/watch?v=9P6rdqiybaw" ``` -------------------------------- ### Golang: Request iframe and palette parameters Source: https://microlink.io/docs/guides/embed/iframe Golang example that constructs a URL with `iframe` and `palette` parameters, sends a GET request, and prints the response body. ```go 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://open.spotify.com/track/3BovdzfaX4jb5KFQwoPfAw") q.Set("iframe", "true") q.Set("palette", "true") 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)) } ``` -------------------------------- ### Target French IP with proxy.location=fr for example.com/pricing Source: https://microlink.io/docs/guides/common/proxy.md Use these examples to request 'https://example.com/pricing' with the 'proxy.location=fr' parameter and an API key. The request is resolved through a French IP; the default location is 'us'. Replace YOUR_API_TOKEN with your actual token. ```bash microlink https://example.com/pricing&proxy.location=fr --api-key YOUR_API_TOKEN ``` ```bash curl -G "https://pro.microlink.io" \ -H "x-api-key: YOUR_API_TOKEN" \ -d "url=https://example.com/pricing" \ -d "proxy.location=fr" \ -d "meta=false" ``` ```javascript import createClient from 'microlink.io' const microlink = createClient({ apiKey: "YOUR_API_TOKEN" }) const data = await microlink.metadata('https://example.com/pricing', { proxy: { location: "fr" } }) ``` ```python import requests url = "https://pro.microlink.io/" querystring = { "url": "https://example.com/pricing", "proxy.location": "fr", "meta": "false" } headers = { "x-api-key": "YOUR_API_TOKEN" } response = requests.get(url, params=querystring, headers=headers) print(response.json()) ``` ```ruby require 'uri' require 'net/http' base_url = "https://pro.microlink.io/" params = { url: "https://example.com/pricing", proxy.location: "fr", meta: "false" } 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) request['x-api-key'] = "YOUR_API_TOKEN" response = http.request(request) puts response.body ``` ```php "https://example.com/pricing", "proxy.location" => "fr", "meta" => "false" ]; $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", CURLOPT_HTTPHEADER => [ "x-api-key: YOUR_API_TOKEN" ] ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #: " . $err; } else { echo $response; } ``` ```go package main import ( "fmt" "net/http" "net/url" "io" ) func main() { baseURL := "https://pro.microlink.io" u, err := url.Parse(baseURL) if err != nil { panic(err) } q := u.Query() q.Set("url", "https://example.com/pricing") q.Set("proxy.location", "fr") q.Set("meta", "false") u.RawQuery = q.Encode() req, err := http.NewRequest("GET", u.String(), nil) if err != nil { panic(err) } req.Header.Set("x-api-key", "YOUR_API_TOKEN") 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)) } ``` -------------------------------- ### cURL Microlink API example Source: https://microlink.io/docs/guides/data-extraction/caching-and-performance cURL example for the Microlink API with cache parameters. Uses `-G` to send GET request with query parameters and `x-api-key` header. ```bash curl -G "https://pro.microlink.io" \ -H "x-api-key: YOUR_API_TOKEN" \ -d "url=https://example.com" \ -d "data.title.selector=h1" \ -d "data.title.attr=text" \ -d "meta=false" \ -d "ttl=1d" \ -d "staleTtl=0" ``` -------------------------------- ### Create client and call function with profiling Source: https://microlink.io/docs/guides/function/profiling-and-performance Shows how to create a Microlink client and call a function, retrieving the profiling size. The SDK automatically compresses the function body. ```javascript import createClient from 'microlink.io' const microlink = createClient() const { value, profiling } = await microlink.function( 'https://example.com', ({ page }) => page.title() ) console.log(profiling.size) ``` -------------------------------- ### Python Microlink API example Source: https://microlink.io/docs/guides/data-extraction/caching-and-performance Python example using `requests` to call the Microlink API with cache parameters. Sends GET request with query parameters and `x-api-key` header. ```python import requests url = "https://pro.microlink.io/" querystring = { "url": "https://example.com", "data.title.selector": "h1", "data.title.attr": "text", "meta": "false", "ttl": "1d", "staleTtl": "0" } headers = { "x-api-key": "YOUR_API_TOKEN" } response = requests.get(url, params=querystring, headers=headers) print(response.json()) ``` -------------------------------- ### Golang Microlink API example Source: https://microlink.io/docs/guides/content-conversion/url-to-text Uses the `net/http` package to send a GET request with query parameters. Prints the response body. ```go 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://example.com") q.Set("data.text.attr", "text") q.Set("meta", "false") q.Set("embed", "text") 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)) } ``` -------------------------------- ### Python Microlink API example Source: https://microlink.io/docs/api/parameters/screenshot/overlay Python example using the 'requests' library to call the Microlink API. It sends a GET request with the 'screenshot.overlay' parameters and prints the JSON response. ```python import requests url = "https://api.microlink.io/" querystring = { "url": "https://www.apple.com/music", "screenshot.overlay.background": "linear-gradient(225deg, #FF057C 0%, #8D0B93 50%, #321575 100%)", "screenshot.overlay.browser": "dark" } response = requests.get(url, params=querystring) print(response.json()) ``` -------------------------------- ### CLI Microlink API example Source: https://microlink.io/docs/api/parameters/prerender CLI example using the Microlink CLI to fetch metadata for the target URL. The prerender parameter is not specified, so the default behavior applies. ```bash microlink https://www.sportsnet.ca/hockey/nhl/leafs-john-tavares-return-new-york-hope-positive ``` -------------------------------- ### GET /?screenshot.type=jpeg Source: https://microlink.io/docs/api/parameters/screenshot/type Example of using the screenshot.type parameter with the Microlink API via cURL. ```APIDOC ## GET /?screenshot.type=jpeg ### Description Specifies the screenshot file type for the screenshot over the target URL. The default value is 'png', and the allowed values are 'jpeg' and 'png'. ### Method GET ### Endpoint https://api.microlink.io/?url={url}&screenshot.type={type} ### Parameters #### Query Parameters - **url** (string) - Required - The target URL to take a screenshot of. - **screenshot.type** (string) - Optional - The screenshot file type. Default: 'png'. Values: 'jpeg' | 'png'. ### Request Example ``` curl -G "https://api.microlink.io" \ -d "url=https://microlink.io" \ -d "screenshot.type=jpeg" ``` ### Response #### Success Response (200) Returns a JSON object containing the screenshot data. #### Response Example ``` { "data": { "screenshot": { "type": "jpeg", "url": "https://cdn.microlink.io/..." } } } ``` ``` -------------------------------- ### Golang Microlink API example with headers parameter Source: https://microlink.io/docs/api/parameters/headers Uses net/http to send GET request with headers.user-agent and headers.accept-language as query parameters. ```go 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") q.Set("headers.user-agent", "googlebot") q.Set("headers.accept-language", "en-US") 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)) } ``` -------------------------------- ### Ruby Microlink API example Source: https://microlink.io/docs/guides/screenshot/embedding Use Ruby's `net/http` library to send a GET request to the Microlink API with `screenshot=true`, `meta=false`, and `embed=screenshot.url` to get the screenshot image directly. ```ruby require 'uri' require 'net/http' base_url = "https://api.microlink.io/" params = { url: "https://github.com/microlinkhq", screenshot: "true", meta: "false", 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.body ``` -------------------------------- ### Golang Microlink API example with waitForSelector Source: https://microlink.io/docs/guides/pdf/page-preparation Golang example using net/http to call the Microlink API with pdf, meta, waitUntil, and waitForSelector parameters. It prints the response body. ```go 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://dev.to") q.Set("pdf", "true") q.Set("meta", "false") q.Set("waitUntil", "domcontentloaded") q.Set("waitForSelector", "article") 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)) } ``` -------------------------------- ### Ruby Microlink API example Source: https://microlink.io/docs/guides/embed Use Ruby with net/http to call the Microlink API. The example builds a URI with the URL parameter, sends a GET request, and prints the response body. ```ruby require 'uri' require 'net/http' base_url = "https://api.microlink.io/" params = { url: "https://www.youtube.com/watch?v=9P6rdqiybaw" } 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.body ``` -------------------------------- ### Ruby Microlink API example with page.metadata Source: https://microlink.io/docs/api/parameters/function Ruby example using the Microlink API with the 'function' parameter for page.metadata(). It builds a GET request with URI encoding and prints the response body. ```ruby require 'uri' require 'net/http' base_url = "https://api.microlink.io/" params = { url: "https://example.com", function: "async ({ page }) => (await page.metadata()).title" } 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.body ``` -------------------------------- ### CLI Microlink API example Source: https://microlink.io/docs/api/parameters/prerender Example of using the prerender parameter via the Microlink CLI. ```bash microlink https://www.sportsnet.ca/hockey/nhl/leafs-john-tavares-return-new-york-hope-positive&prerender=auto ``` -------------------------------- ### Server/RSC/build-time preview helper Source: https://microlink.io/docs/guides/embed/custom-previews-with-ai Creates a Microlink client and exports a `getPreview` function that fetches metadata with palette enabled. Use in server components or at build time. ```javascript import createClient from 'microlink.io' const microlink = createClient() export async function getPreview(url, options = {}) { return microlink.metadata(url, { palette: true, ...options }) } ``` ```javascript // app/components/LinkPreview.tsx (Next.js RSC example) import { getPreview } from '@/lib/preview' export async function LinkPreview({ url }) { const data = await getPreview(url) return /* the JSX your assistant generated, reading from `data` */ } ``` -------------------------------- ### GET https://api.microlink.io Source: https://microlink.io/docs/guides/pdf/page-size-and-layout Example of using the Microlink API to generate a PDF with landscape orientation. ```APIDOC ## [GET] https://api.microlink.io ### Description Generates a PDF of the specified URL with landscape orientation using the `pdf.landscape` parameter. The `meta` parameter is set to `false` to disable metadata extraction. ### Method GET ### Endpoint https://api.microlink.io ### Parameters #### Query Parameters - **url** (string) - Required - The URL to generate a PDF from. - **pdf.landscape** (boolean) - Required - Set to `true` to enable landscape orientation. - **meta** (boolean) - Optional - Set to `false` to disable metadata extraction. ### Request Example ``` curl -G "https://api.microlink.io" \ -d "url=https://www.algolia.com" \ -d "pdf.landscape=true" \ -d "meta=false" ``` ### Response #### Success Response (200) - **data** (object) - Contains the PDF data and metadata. #### Response Example ```json { "data": { "pdf": "...", "meta": null } } ``` ```