function
The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://microlink.io' URL with 'function' & 'scripts' API parameters:
CLI Microlink API example
microlink https://microlink.io&function='({ page }) => page.evaluate("jQuery.fn.jquery")'&scripts=https://code.jquery.com/jquery-3.5.0.min.jscURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://microlink.io" \
-d "function=(%7B%20page%20%7D)%20%3D%3E%20page.evaluate(%22jQuery.fn.jquery%22)" \
-d "scripts=https://code.jquery.com/jquery-3.5.0.min.js"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://microlink.io', {
function: '({ page }) => page.evaluate("jQuery.fn.jquery")',
scripts: [
"https://code.jquery.com/jquery-3.5.0.min.js"
]
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://microlink.io",
"function": '''({ page }) => page.evaluate("jQuery.fn.jquery")''',
"scripts": "https://code.jquery.com/jquery-3.5.0.min.js"
}
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",
function: '({ page }) => page.evaluate("jQuery.fn.jquery")',
scripts: "https://code.jquery.com/jquery-3.5.0.min.js"
}
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",
"function" => '({ page }) => page.evaluate("jQuery.fn.jquery")',
"scripts" => "https://code.jquery.com/jquery-3.5.0.min.js"
];
$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.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))
}import mql from '@microlink/mql'
const { data } = await mql('https://microlink.io', {
function: '({ page }) => page.evaluate("jQuery.fn.jquery")',
scripts: [
"https://code.jquery.com/jquery-3.5.0.min.js"
]
})Page
page, Microlink navigates to the URL in a browser before calling your function. Any Puppeteer page method is available:The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://example.com' URL with 'function' & 'meta' API parameters:
CLI Microlink API example
microlink https://example.com&function='({ page }) => page.title()'cURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://example.com" \
-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://example.com', {
function: "({ page }) => page.title()",
meta: false
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://example.com",
"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://example.com",
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://example.com",
"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://example.com")
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://example.com', {
function: "({ page }) => page.title()",
meta: false
})The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://example.com' URL with 'function' & 'meta' API parameters:
CLI Microlink API example
microlink https://example.com&function='({ page }) => page.$eval('"'"'h1'"'"', el => el.textContent)'cURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://example.com" \
-d "function=(%7B%20page%20%7D)%20%3D%3E%20page.%24eval('h1'%2C%20el%20%3D%3E%20el.textContent)" \
-d "meta=false"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://example.com', {
function: "({ page }) => page.$eval('h1', el => el.textContent)",
meta: false
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://example.com",
"function": '''({ page }) => page.$eval('h1', el => el.textContent)''',
"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://example.com",
function: "({ page }) => page.$eval('h1', el => el.textContent)",
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://example.com",
"function" => "({ page }) => page.$eval('h1', el => el.textContent)",
"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.$eval('h1', el => el.textContent)`
q := u.Query()
q.Set("url", "https://example.com")
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://example.com', {
function: "({ page }) => page.$eval('h1', el => el.textContent)",
meta: false
})The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://example.com' URL with 'function' & 'meta' API parameters:
CLI Microlink API example
microlink https://example.com&function='({ page }) => page.$$eval('"'"'a'"'"', links => links.map(a => a.href))'cURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://example.com" \
-d "function=(%7B%20page%20%7D)%20%3D%3E%20page.%24%24eval('a'%2C%20links%20%3D%3E%20links.map(a%20%3D%3E%20a.href))" \
-d "meta=false"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://example.com', {
function: "({ page }) => page.$$eval('a', links => links.map(a => a.href))",
meta: false
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://example.com",
"function": '''({ page }) => page.$$eval('a', links => links.map(a => a.href))''',
"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://example.com",
function: "({ page }) => page.$$eval('a', links => links.map(a => a.href))",
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://example.com",
"function" => "({ page }) => page.$$eval('a', links => links.map(a => a.href))",
"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.$$eval('a', links => links.map(a => a.href))`
q := u.Query()
q.Set("url", "https://example.com")
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://example.com', {
function: "({ page }) => page.$$eval('a', links => links.map(a => a.href))",
meta: false
})The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://example.com' URL with 'function' & 'meta' API parameters:
CLI Microlink API example
microlink https://example.com&function='({ page }) => page.evaluate(() => ({
viewport: { width: window.innerWidth, height: window.innerHeight },
cookies: document.cookie.length,
resources: performance.getEntriesByType('"'"'resource'"'"').length
}))'cURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://example.com" \
-d "function=(%7B%20page%20%7D)%20%3D%3E%20page.evaluate(()%20%3D%3E%20(%7B%0A%20%20viewport%3A%20%7B%20width%3A%20window.innerWidth%2C%20height%3A%20window.innerHeight%20%7D%2C%0A%20%20cookies%3A%20document.cookie.length%2C%0A%20%20resources%3A%20performance.getEntriesByType('resource').length%0A%7D))" \
-d "meta=false"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://example.com', {
function: "({ page }) => page.evaluate(() => ({
viewport: { width: window.innerWidth, height: window.innerHeight },
cookies: document.cookie.length,
resources: performance.getEntriesByType('resource').length
}))",
meta: false
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://example.com",
"function": '''({ page }) => page.evaluate(() => ({
viewport: { width: window.innerWidth, height: window.innerHeight },
cookies: document.cookie.length,
resources: performance.getEntriesByType('resource').length
}))''',
"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://example.com",
function: "({ page }) => page.evaluate(() => ({
viewport: { width: window.innerWidth, height: window.innerHeight },
cookies: document.cookie.length,
resources: performance.getEntriesByType('resource').length
}))",
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://example.com",
"function" => "({ page }) => page.evaluate(() => ({
viewport: { width: window.innerWidth, height: window.innerHeight },
cookies: document.cookie.length,
resources: performance.getEntriesByType('resource').length
}))",
"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.evaluate(() => ({
viewport: { width: window.innerWidth, height: window.innerHeight },
cookies: document.cookie.length,
resources: performance.getEntriesByType('resource').length
}))`
q := u.Query()
q.Set("url", "https://example.com")
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://example.com', {
function: "({ page }) => page.evaluate(() => ({
viewport: { width: window.innerWidth, height: window.innerHeight },
cookies: document.cookie.length,
resources: performance.getEntriesByType('resource').length
}))",
meta: false
})page.evaluate.Response
page:The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://edge-ping.vercel.app' URL with 'function' & 'meta' API parameters:
CLI Microlink API example
microlink https://edge-ping.vercel.app&function='({ page, response }) => response.status()'cURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://edge-ping.vercel.app" \
-d "function=(%7B%20page%2C%20response%20%7D)%20%3D%3E%20response.status()" \
-d "meta=false"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://edge-ping.vercel.app', {
function: "({ page, response }) => response.status()",
meta: false
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://edge-ping.vercel.app",
"function": "({ page, response }) => response.status()",
"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://edge-ping.vercel.app",
function: "({ page, response }) => response.status()",
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://edge-ping.vercel.app",
"function" => "({ page, response }) => response.status()",
"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://edge-ping.vercel.app")
q.Set("function", "({ page, response }) => response.status()")
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://edge-ping.vercel.app', {
function: "({ page, response }) => response.status()",
meta: false
})Headers
The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://example.com' URL with 'function' & 'meta' API parameters:
CLI Microlink API example
microlink https://example.com&function='({ headers }) => headers["user-agent"]'cURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://example.com" \
-d "function=(%7B%20headers%20%7D)%20%3D%3E%20headers%5B%22user-agent%22%5D" \
-d "meta=false"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://example.com', {
function: '({ headers }) => headers["user-agent"]',
meta: false
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://example.com",
"function": '''({ headers }) => headers["user-agent"]''',
"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://example.com",
function: '({ headers }) => headers["user-agent"]',
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://example.com",
"function" => '({ headers }) => headers["user-agent"]',
"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 := `({ headers }) => headers["user-agent"]`
q := u.Query()
q.Set("url", "https://example.com")
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://example.com', {
function: '({ headers }) => headers["user-agent"]',
meta: false
})Custom parameters
The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://example.com' URL with 'function', 'greetings' & 'meta' API parameters:
CLI Microlink API example
microlink https://example.com&function='({ greetings }) => greetings'&greetings='hello world'cURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://example.com" \
-d "function=(%7B%20greetings%20%7D)%20%3D%3E%20greetings" \
-d "greetings=hello%20world" \
-d "meta=false"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://example.com', {
function: "({ greetings }) => greetings",
greetings: "hello world",
meta: false
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://example.com",
"function": "({ greetings }) => greetings",
"greetings": "hello world",
"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://example.com",
function: "({ greetings }) => greetings",
greetings: "hello world",
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://example.com",
"function" => "({ greetings }) => greetings",
"greetings" => "hello world",
"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://example.com")
q.Set("function", "({ greetings }) => greetings")
q.Set("greetings", "hello world")
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://example.com', {
function: "({ greetings }) => greetings",
greetings: "hello world",
meta: false
})Response
data.function:{
"status": "success",
"data": {
"function": {
"isFulfilled": true,
"value": "3.5.0",
"profiling": {
"phases": { "install": 0, "build": 120, "spawn": 45, "run": 890, "total": 1055 },
"cpu": 234,
"memory": 8,
"size": 156
},
"logging": {}
}
}
}| Field | Description |
|---|---|
isFulfilled | true when the function completed without errors |
value | The return value on success, or { name, message } on failure |
profiling | Execution metrics: phase durations (ms), peak CPU time (ms), memory (MB), and code size (bytes) |
logging | Captured console output from the function runtime |
| Phase | Description |
|---|---|
install | Time spent installing npm dependencies detected in your code |
build | Time spent bundling the function code |
spawn | Time spent starting the isolated runtime process |
run | Time spent executing the function itself |
total | Wall-clock time from start to finish |
Plan limits
| Free | Pro | |
|---|---|---|
| Timeout | 5 seconds | Up to 28 seconds |
| Memory | 16 MB | 32 MB |
| Code size | 1024 bytes | Unlimited |
| Concurrency | 1 per IP | Unlimited |
isFulfilled: false with a descriptive error instead of failing the entire request:{
"data": {
"function": {
"isFulfilled": false,
"value": {
"name": "TimeoutError",
"message": "Function exceeded the 5s free plan timeout. Upgrade to pro for up to 28s."
},
"profiling": {},
"logging": {}
}
}
}| Error | Trigger |
|---|---|
TimeoutError | Function wall-clock time exceeded the plan limit |
CpuTimeError | Function CPU time exceeded the plan limit |
MemoryError | Function memory usage exceeded the plan limit |
CodeSizeError | Function code exceeds the 1024 bytes free plan limit |
ConcurrencyError | Too many concurrent function executions for the free plan (1 per IP) |
Compression
const { compressToURI } = require('lz-ts')
const mql = require('@microlink/mql')
const code = ({ page }) => page.evaluate("jQuery.fn.jquery")
const { status, data } = await mql('https://microlink.io', {
function: `lz#${compressToURI(code.toString())}`,
meta: false,
scripts: 'https://code.jquery.com/jquery-3.5.0.min.js'
})
mql.render(data.function)- brotli (
br) - gzip (
gz) - lz-string (
lz)
NPM packages
require() for any npm package. Dependencies are detected automatically from your code and installed on-the-fly during the install phase.const mql = require('@microlink/mql')
const code = () => {
const cheerio = require('cheerio')
const $ = cheerio.load('<h1>Hello world</h1>')
return $('h1').text()
}
const { data } = await mql('https://example.com', {
function: code.toString(),
meta: false
})Function constructor
function is through the const microlink = require('@microlink/function')
const getTitle = microlink(({ page }) => page.title())
const result = await getTitle('https://example.com')
console.log(result.value) // 'Example Domain'