Function
function parameter is Microlink's escape hatch. When data, metadata, screenshot, or pdf gets you close but not all the way, you can send JavaScript that Microlink executes remotely inside the same headless Chromium request.data.function, with the resolved value at data.function.value.Your first function
page.title():The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://developer.mozilla.org/en-US/docs/Web/API/Document/title' URL with 'function' & 'meta' API parameters:
CLI Microlink API example
microlink https://developer.mozilla.org/en-US/docs/Web/API/Document/title&function='({ page }) => page.title()'cURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://developer.mozilla.org/en-US/docs/Web/API/Document/title" \
-d "function=(%7B%20page%20%7D)%20%3D%3E%20page.title()" \
-d "meta=false"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://developer.mozilla.org/en-US/docs/Web/API/Document/title', {
function: "({ page }) => page.title()",
meta: false
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://developer.mozilla.org/en-US/docs/Web/API/Document/title",
"function": "({ page }) => page.title()",
"meta": "false"
}
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://developer.mozilla.org/en-US/docs/Web/API/Document/title",
function: "({ page }) => page.title()",
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)
response = http.request(request)
puts response.bodyPHP Microlink API example
<?php
$baseUrl = "https://api.microlink.io/";
$params = [
"url" => "https://developer.mozilla.org/en-US/docs/Web/API/Document/title",
"function" => "({ page }) => page.title()",
"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"
]);
$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://developer.mozilla.org/en-US/docs/Web/API/Document/title")
q.Set("function", "({ page }) => page.title()")
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))
}import mql from '@microlink/mql'
const { data } = await mql('https://developer.mozilla.org/en-US/docs/Web/API/Document/title', {
function: "({ page }) => page.title()",
meta: false
})data.function.value. The examples in this guide use fully public pages and meta: false to keep them friendly to the free plan.{
"status": "success",
"data": {
"function": {
"isFulfilled": true,
"value": "Document: title property - Web APIs | MDN"
}
}
}MQL installation
@microlink/mql:npm install @microlink/mql --save@microlink/functioncode.toString() yourself.How function execution works
- Microlink opens the target
urlin headless Chromium. - The request can also include page-preparation parameters such as
scripts,modules,click, orwaitForSelector. - Microlink calls your function with
page,response,html, and any extra parameters you passed in the request. - Whatever your function returns or resolves to is wrapped into
data.function, and the actual result is available atdata.function.value.
function is just another Microlink parameter, you can also combine it with other workflows in the same request, such as screenshot: true or pdf: true, when you need custom page preparation before generating the final output.Choose the lightest tool
function when the built-in parameters stop being expressive enough, not as the default for every workflow.| If you need | Best option | Why |
|---|---|---|
| Simple field extraction from the DOM | data | Declarative rules are shorter, easier to maintain, and easier to reuse |
| Inject CSS or JavaScript before another workflow | styles, modules, or scripts | Lighter than full browser automation |
| Click, wait, compute, reshape, or orchestrate custom logic | function | You get Puppeteer access plus a curated require() allowlist |
function when the declarative approach becomes limiting.What your function receives
| Property | Type | Description |
|---|---|---|
page | Page | Full Puppeteer access for clicks, waits, evaluation, navigation, and page inspection |
response | HTTPResponse | The response returned by the implicit navigation |
html | string | Page markup when available. If you disable metadata and still need HTML, prefer page.content() |
| any extra parameter | depends on what you pass | Custom inputs such as selectors, flags, thresholds, or field names |
page helpers such as page.title(), page.$eval(), or page.$$eval(). They are easier to read and easier to debug than reaching for a large page.evaluate(...) block immediately.Pass your own parameters
The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://developer.mozilla.org/en-US/docs/Web/API/Document/title' URL with 'function', 'label' & 'meta' API parameters:
CLI Microlink API example
microlink https://developer.mozilla.org/en-US/docs/Web/API/Document/title&function='({ page, label }) =>
page.title().then(title => ({ label, title }))'&label='Current page title'cURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://developer.mozilla.org/en-US/docs/Web/API/Document/title" \
-d "function=(%7B%20page%2C%20label%20%7D)%20%3D%3E%0A%20%20page.title().then(title%20%3D%3E%20(%7B%20label%2C%20title%20%7D))" \
-d "label=Current%20page%20title" \
-d "meta=false"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://developer.mozilla.org/en-US/docs/Web/API/Document/title', {
function: "({ page, label }) =>
page.title().then(title => ({ label, title }))",
label: "Current page title",
meta: false
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://developer.mozilla.org/en-US/docs/Web/API/Document/title",
"function": '''({ page, label }) =>
page.title().then(title => ({ label, title }))''',
"label": "Current page title",
"meta": "false"
}
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://developer.mozilla.org/en-US/docs/Web/API/Document/title",
function: "({ page, label }) =>
page.title().then(title => ({ label, title }))",
label: "Current page title",
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)
response = http.request(request)
puts response.bodyPHP Microlink API example
<?php
$baseUrl = "https://api.microlink.io/";
$params = [
"url" => "https://developer.mozilla.org/en-US/docs/Web/API/Document/title",
"function" => "({ page, label }) =>
page.title().then(title => ({ label, title }))",
"label" => "Current page title",
"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"
]);
$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)
}
fn := `({ page, label }) =>
page.title().then(title => ({ label, title }))`
q := u.Query()
q.Set("url", "https://developer.mozilla.org/en-US/docs/Web/API/Document/title")
q.Set("function", fn)
q.Set("label", "Current page title")
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))
}import mql from '@microlink/mql'
const { data } = await mql('https://developer.mozilla.org/en-US/docs/Web/API/Document/title', {
function: "({ page, label }) =>
page.title().then(title => ({ label, title }))",
label: "Current page title",
meta: false
})label parameter is forwarded into the function. This is the simplest way to make one function reusable across different requests.Two execution contexts
| Code runs in | Good for | Can access |
|---|---|---|
The outer function body | Orchestration, Puppeteer calls, require(), and response shaping | page, response, forwarded params, and allowed npm packages |
page.evaluate(...) | Reading or computing values from the live DOM when page helpers are not enough | window, document, performance, and page state |
page.title(), page.$eval(), and page.$$eval(). Reach for page.evaluate(...) only when the logic truly belongs inside the page context. Do not rely on require() inside page.evaluate.Return structured data
The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://developer.mozilla.org/en-US/docs/Web/API/Document/title' URL with 'function' & 'meta' API parameters:
CLI Microlink API example
microlink https://developer.mozilla.org/en-US/docs/Web/API/Document/title&function='({ page }) =>
page.title().then(title => ({
title,
titleLength: title.length,
words: title.split(/\s+/)
}))'cURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://developer.mozilla.org/en-US/docs/Web/API/Document/title" \
-d "function=(%7B%20page%20%7D)%20%3D%3E%0A%20%20page.title().then(title%20%3D%3E%20(%7B%0A%20%20%20%20title%2C%0A%20%20%20%20titleLength%3A%20title.length%2C%0A%20%20%20%20words%3A%20title.split(%2F%5Cs%2B%2F)%0A%20%20%7D))" \
-d "meta=false"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://developer.mozilla.org/en-US/docs/Web/API/Document/title', {
function: "({ page }) =>
page.title().then(title => ({
title,
titleLength: title.length,
words: title.split(/\s+/)
}))",
meta: false
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://developer.mozilla.org/en-US/docs/Web/API/Document/title",
"function": '''({ page }) =>
page.title().then(title => ({
title,
titleLength: title.length,
words: title.split(/\s+/)
}))''',
"meta": "false"
}
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://developer.mozilla.org/en-US/docs/Web/API/Document/title",
function: "({ page }) =>
page.title().then(title => ({
title,
titleLength: title.length,
words: title.split(/\s+/)
}))",
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)
response = http.request(request)
puts response.bodyPHP Microlink API example
<?php
$baseUrl = "https://api.microlink.io/";
$params = [
"url" => "https://developer.mozilla.org/en-US/docs/Web/API/Document/title",
"function" => "({ page }) =>
page.title().then(title => ({
title,
titleLength: title.length,
words: title.split(/\s+/)
}))",
"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"
]);
$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)
}
fn := `({ page }) =>
page.title().then(title => ({
title,
titleLength: title.length,
words: title.split(/\s+/)
}))`
q := u.Query()
q.Set("url", "https://developer.mozilla.org/en-US/docs/Web/API/Document/title")
q.Set("function", fn)
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))
}import mql from '@microlink/mql'
const { data } = await mql('https://developer.mozilla.org/en-US/docs/Web/API/Document/title', {
function: "({ page }) =>
page.title().then(title => ({
title,
titleLength: title.length,
words: title.split(/\s+/)
}))",
meta: false
})When you really need page.evaluate
page.evaluate(...) when the information only exists inside the live browser page:const { data } = await mql('https://developer.mozilla.org/en-US/docs/Web/API/Document/title', {
function: `({ page }) => page.evaluate(() => ({
heading: document.querySelector('main h1')?.textContent?.trim(),
codeExamples: document.querySelectorAll('pre').length
}))`,
meta: false
})
console.log(data.function.value)page.title() or page.$eval(). Start with the page helpers first, then move into page.evaluate(...) when you need direct access to document, window, or browser-only APIs.Use npm packages
require() a curated allowlist of packages. That makes it useful for parsing, retries, HTML processing, HTTP calls, and response shaping without running your own serverless infrastructure.The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://developer.mozilla.org/en-US/docs/Web/API/Document/title' URL with 'function' & 'meta' API parameters:
CLI Microlink API example
microlink https://developer.mozilla.org/en-US/docs/Web/API/Document/title&function='({ page }) =>
page.title().then(title => {
const { words, kebabCase } = require('"'"'lodash'"'"')
return {
title,
words: words(title),
slug: kebabCase(title)
}
})'cURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://developer.mozilla.org/en-US/docs/Web/API/Document/title" \
-d "function=(%7B%20page%20%7D)%20%3D%3E%0A%20%20page.title().then(title%20%3D%3E%20%7B%0A%20%20%20%20const%20%7B%20words%2C%20kebabCase%20%7D%20%3D%20require('lodash')%0A%20%20%20%20return%20%7B%0A%20%20%20%20%20%20title%2C%0A%20%20%20%20%20%20words%3A%20words(title)%2C%0A%20%20%20%20%20%20slug%3A%20kebabCase(title)%0A%20%20%20%20%7D%0A%20%20%7D)" \
-d "meta=false"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://developer.mozilla.org/en-US/docs/Web/API/Document/title', {
function: "({ page }) =>
page.title().then(title => {
const { words, kebabCase } = require('lodash')
return {
title,
words: words(title),
slug: kebabCase(title)
}
})",
meta: false
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://developer.mozilla.org/en-US/docs/Web/API/Document/title",
"function": '''({ page }) =>
page.title().then(title => {
const { words, kebabCase } = require('lodash')
return {
title,
words: words(title),
slug: kebabCase(title)
}
})''',
"meta": "false"
}
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://developer.mozilla.org/en-US/docs/Web/API/Document/title",
function: "({ page }) =>
page.title().then(title => {
const { words, kebabCase } = require('lodash')
return {
title,
words: words(title),
slug: kebabCase(title)
}
})",
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)
response = http.request(request)
puts response.bodyPHP Microlink API example
<?php
$baseUrl = "https://api.microlink.io/";
$params = [
"url" => "https://developer.mozilla.org/en-US/docs/Web/API/Document/title",
"function" => "({ page }) =>
page.title().then(title => {
const { words, kebabCase } = require('lodash')
return {
title,
words: words(title),
slug: kebabCase(title)
}
})",
"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"
]);
$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)
}
fn := `({ page }) =>
page.title().then(title => {
const { words, kebabCase } = require('lodash')
return {
title,
words: words(title),
slug: kebabCase(title)
}
})`
q := u.Query()
q.Set("url", "https://developer.mozilla.org/en-US/docs/Web/API/Document/title")
q.Set("function", fn)
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))
}import mql from '@microlink/mql'
const { data } = await mql('https://developer.mozilla.org/en-US/docs/Web/API/Document/title', {
function: "({ page }) =>
page.title().then(title => {
const { words, kebabCase } = require('lodash')
return {
title,
words: words(title),
slug: kebabCase(title)
}
})",
meta: false
})lodash. Here it turns the page title into both an array of words and a slug-like string.cheerio, lodash, got, jsdom, @mozilla/readability, ioredis, and metascraper. See the function reference for the documented allowlist.Skip metadata for faster runs
meta: false:The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://developer.mozilla.org/en-US/docs/Web/API/Document/title' URL with 'function' & 'meta' API parameters:
CLI Microlink API example
microlink https://developer.mozilla.org/en-US/docs/Web/API/Document/title&function='({ page }) => page.title()'cURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://developer.mozilla.org/en-US/docs/Web/API/Document/title" \
-d "function=(%7B%20page%20%7D)%20%3D%3E%20page.title()" \
-d "meta=false"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://developer.mozilla.org/en-US/docs/Web/API/Document/title', {
function: "({ page }) => page.title()",
meta: false
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://developer.mozilla.org/en-US/docs/Web/API/Document/title",
"function": "({ page }) => page.title()",
"meta": "false"
}
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://developer.mozilla.org/en-US/docs/Web/API/Document/title",
function: "({ page }) => page.title()",
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)
response = http.request(request)
puts response.bodyPHP Microlink API example
<?php
$baseUrl = "https://api.microlink.io/";
$params = [
"url" => "https://developer.mozilla.org/en-US/docs/Web/API/Document/title",
"function" => "({ page }) => page.title()",
"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"
]);
$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://developer.mozilla.org/en-US/docs/Web/API/Document/title")
q.Set("function", "({ page }) => page.title()")
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))
}import mql from '@microlink/mql'
const { data } = await mql('https://developer.mozilla.org/en-US/docs/Web/API/Document/title', {
function: "({ page }) => page.title()",
meta: false
})page.content() inside the function instead of enabling metadata just to read the page HTML.Compress large functions
const { compressToURI } = require('lz-ts')
const mql = require('@microlink/mql')
const code = ({ page }) => page.title()
const { data } = await mql('https://developer.mozilla.org/en-US/docs/Web/API/Document/title', {
function: `lz#${compressToURI(code.toString())}`,
meta: false
})
console.log(data.function.value)lz#for lz-stringbr#for brotligz#for gzip
Free tier, API key, and local testing
headers, proxy, ttl, or staleTtl, those controls require a x-api-key:The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://developer.mozilla.org/en-US/docs/Web/API/Document/title' URL with 'function', 'meta' & 'apiKey' API parameters:
CLI Microlink API example
microlink https://developer.mozilla.org/en-US/docs/Web/API/Document/title&function='({ page }) => page.title()' --api-key YOUR_API_TOKENcURL Microlink API example
curl -G "https://api.microlink.io" \
-H "x-api-key: YOUR_API_TOKEN" \
-d "url=https://developer.mozilla.org/en-US/docs/Web/API/Document/title" \
-d "function=(%7B%20page%20%7D)%20%3D%3E%20page.title()" \
-d "meta=false"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://developer.mozilla.org/en-US/docs/Web/API/Document/title', {
function: "({ page }) => page.title()",
meta: false,
apiKey: "YOUR_API_TOKEN"
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://developer.mozilla.org/en-US/docs/Web/API/Document/title",
"function": "({ page }) => page.title()",
"meta": "false"
}
headers = {
"x-api-key": "YOUR_API_TOKEN"
}
response = requests.get(url, params=querystring, headers=headers)
print(response.json())Ruby Microlink API example
require 'uri'
require 'net/http'
base_url = "https://api.microlink.io/"
params = {
url: "https://developer.mozilla.org/en-US/docs/Web/API/Document/title",
function: "({ page }) => page.title()",
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.bodyPHP Microlink API example
<?php
$baseUrl = "https://api.microlink.io/";
$params = [
"url" => "https://developer.mozilla.org/en-US/docs/Web/API/Document/title",
"function" => "({ page }) => page.title()",
"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;
}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://developer.mozilla.org/en-US/docs/Web/API/Document/title")
q.Set("function", "({ page }) => page.title()")
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))
}import mql from '@microlink/mql'
const { data } = await mql('https://developer.mozilla.org/en-US/docs/Web/API/Document/title', {
function: "({ page }) => page.title()",
meta: false,
apiKey: "YOUR_API_TOKEN"
})Common failure modes
EINVALFUNCTION— the function string has invalid JavaScript syntax. Check quotes, brackets, template strings, and arrow function formatting.EINVALEVAL— the function executed but threw at runtime. Check undefined variables, DOM queries that returnnull, or mistakes insidepage.evaluate.
- Reduce it to a trivial check such as
({ page }) => page.title(). - Set
meta: falseunless metadata is part of the requirement. - Replace fixed waits with
waitForSelectorwhenever possible. - Move DOM-only code into
page.evaluate, and keep orchestration in the outer function.
What's next
- Common troubleshooting — debug timeouts, blocked sites, and plan/auth problems.
- Common caching patterns — reduce cost and improve response speed once the function logic is stable.
- Common private pages — run functions against logged-in, session-based, or personalized pages safely.
- Production patterns — add retries, endpoint selection, and monitoring for real integrations.
See also
- Data extraction — if declarative rules are enough and you want the simplest possible extraction workflow.
- Screenshot: page interaction — if you mainly need to prepare a page before taking a screenshot.
- PDF: page preparation — if your real goal is to clean up or wait for the page before printing to PDF.