Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@microlink/mql

Package Overview
Dependencies
Maintainers
1
Versions
202
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@microlink/mql

Microlink Query Language

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
74K
increased by117.51%
Maintainers
1
Weekly downloads
 
Created
Source

microlink logo

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)
  // => success
})()

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)
  // => false

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

Error Handling

If something does not go as expected, it returns 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 (err) {
    err instanceof MicrolinkError
    // => true
  }
})()

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

Keywords

FAQs

Package last updated on 24 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc