Microlink Query Language (MQL) is the way to interact with the Microlink API.
Install
npm install @microlink/mql
Getting Started
The purpose of the library is to provide a good developer experience while you interact with Microlink API.
You can do exactly the same thing than performing a cURL or any other HTTP client.
const mql = require('@microlink/mql')
;(async () => {
const { status, data, response } = await mql('https://kikobeats.com')
console.log(status)
})()
Additionally, you pass the same API Parameters.
const mql = require('@microlink/mql')
;(async () => {
const { status, data, response } = await mql('https://kikobeats.com', {
screenshot: true,
waitFor: 3000
})
console.log(`My screenshot at ${data.screenshot.url}`)
})()
Cache Support
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)
data = await mql('https://kikobeats.com', { cache })
console.log(data.response.fromCache)
})()
Error Handling
If something does not go as expected, it returns a MicrolinkError
const mql = require('@microlink/mql')
const { MicrolinkError } = mql
;(async () => {
try {
mql('https://kikobeats.com', {
screenshot: true,
waitFor: 30000
})
} catch (err) {
err instanceof MicrolinkError
}
})()
A MicrolinkError
always have associated status
, message
and code
.
Additionally, it can have the rest of the response information, such as headers
, statusCode
or data
.
API
mql(url, [opts])
url
Required
Type: string
The target URL for extracting structure data.
options
Type: object
You can pass any API Parameters from Microlink API as option, including specific parameters or device emulation.
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.
Read more about authentication on docs.
cache
Type: string
Default: undefined
retry
Type: number
Default: 3
See got#retry.
timeout
Type: number
Default: 25000
See got#timeout.
License
mql © microlink.io, released under the MIT License.
Authored and maintained by microlink.io with help from contributors.
microlink.io · GitHub microlink.io · Twitter @microlinkhq