Usage

For using MQL, you need to provide at least a target url
const mql = require('@microlink/mql')

const { status, data, response } = await mql('https://microlink.io')
It will returns a object with the following properties:
  • status: The status associated with the response.
  • data: The data response from the API.
  • response: The Node.js response object.
If something does not go as expected (thas means API returns a status different to success) it will throws a MicrolinkError
const mql = require('@microlink/mql')

// The library exposes `MicrolinkError` constructor
const { MicrolinkError } = mql

;(async () => {
  try {
    mql('https://kikobeats.com', {
      screenshot: true,
      waitFor: 30000
    })
  } catch (error) {
    console.log(error instanceof MicrolinkError) // => true
    console.log(error.name) // => RequestError
    console.log(error.hostname) // => api.microlink.io
    console.log(error.status) // => fail
    console.log(error.url) // => 'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com&screenshot=true&video=true&waitFor=40000&force=true'
    console.log(error.code) // => EFAILED
    console.log(error.message) // => EFAILED, Request timed out
    console.log(error.statusCode) // => 500
  }
})()

A `MicrolinkError` always have associated `status`, `message` and `code`.

API

const mql = require('@microlink/mql')

const { status, data,response } = mql(url, [options])

url

Required
Type: string
The target URL for getting content.

options

Type: object
You can pass any API Parameters from Microlink API as option
const { status, data, response } = await mql('https://kikobeats.com', {
  screenshot: 'iPad',
  palette: true,
  waitFor: 3000
})

console.log(`My screenshot at ${data.screenshot.url}`)
Additionally, you can setup:

apiKey

Type: string
Default: undefined
The API Key used for authenticating your requests as x-api-key header.
When the apiKey is provided, the pro.microlink.io endpoint will used.

cache

Type: string
Default: undefined
You can enable cache for saving API calls if they have been previously done
const mql = require('@microlink/mql')
const cache = new Map()

;(async () => {
  let data

  data = await mql('https://kikobeats.com', { cache })
  console.log(data.response.fromCache)
  // => false

  data = await mql('https://kikobeats.com', { cache })
  console.log(data.response.fromCache)
  // => true
})()
It's just available on the Node.js bundle.

retry

Type: number
Default: 3

timeout

Type: number
Default: 25000

Usage

For using MQL, you need to provide at least a target url
const mql = require('@microlink/mql')

const { status, data, response } = await mql('https://microlink.io')
It will returns a object with the following properties:
  • status: The status associated with the response.
  • data: The data response from the API.
  • response: The Node.js response object.
If something does not go as expected (thas means API returns a status different to success) it will throws a MicrolinkError
const mql = require('@microlink/mql')

// The library exposes `MicrolinkError` constructor
const { MicrolinkError } = mql

;(async () => {
  try {
    mql('https://kikobeats.com', {
      screenshot: true,
      waitFor: 30000
    })
  } catch (error) {
    console.log(error instanceof MicrolinkError) // => true
    console.log(error.name) // => RequestError
    console.log(error.hostname) // => api.microlink.io
    console.log(error.status) // => fail
    console.log(error.url) // => 'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com&screenshot=true&video=true&waitFor=40000&force=true'
    console.log(error.code) // => EFAILED
    console.log(error.message) // => EFAILED, Request timed out
    console.log(error.statusCode) // => 500
  }
})()

A `MicrolinkError` always have associated `status`, `message` and `code`.

API

const mql = require('@microlink/mql')

const { status, data,response } = mql(url, [options])

url

Required
Type: string
The target URL for getting content.

options

Type: object
You can pass any API Parameters from Microlink API as option
const { status, data, response } = await mql('https://kikobeats.com', {
  screenshot: 'iPad',
  palette: true,
  waitFor: 3000
})

console.log(`My screenshot at ${data.screenshot.url}`)
Additionally, you can setup:

apiKey

Type: string
Default: undefined
The API Key used for authenticating your requests as x-api-key header.
When the apiKey is provided, the pro.microlink.io endpoint will used.

cache

Type: string
Default: undefined
You can enable cache for saving API calls if they have been previously done
const mql = require('@microlink/mql')
const cache = new Map()

;(async () => {
  let data

  data = await mql('https://kikobeats.com', { cache })
  console.log(data.response.fromCache)
  // => false

  data = await mql('https://kikobeats.com', { cache })
  console.log(data.response.fromCache)
  // => true
})()
It's just available on the Node.js bundle.

retry

Type: number
Default: 3

timeout

Type: number
Default: 25000