Microlink API, How to use it
Dec 14, 2024Microlink API is a powerful tool for automating browser actions, offering a high-level API to control a headless browser. It's designed for businesses and developers and is proudly open-source.
Microlink API: A Comprehensive Guide
Microlink API is a powerful tool for automating browser actions, offering a high-level API to control a headless browser. It's designed for businesses and developers and is proudly open-source. This article will explore its capabilities and how to use it effectively.
What Microlink API Does
Microlink API allows you to perform a wide range of actions on websites via a simple API call. Key functionalities include:
- Metadata Extraction: Retrieve structured data like title, description, author, and more from any URL.
- Screenshot Generation: Capture screenshots of websites, customizable by device and other parameters.
- PDF Generation: Create PDFs from web pages.
- Tech Stack Identification: Determine the technologies used on a website.
- HTML Markup Retrieval: Obtain the HTML markup of a webpage.
- Embeddable Content: Easily embed content directly into your HTML.
- Color Palette Extraction: Get the predominant color palette from images on a page.
- Prerendering: Retrieve information from websites using client-side frameworks.
Getting Started
To use the Microlink API, you'll need to register an account and obtain an API key. Once you have your key, you can make requests to the API. The API can be accessed directly from your browser or any environment supporting HTTP GET requests. The Microlink CLI is helpful for local development.
Using the API
The API accepts a URL as input and returns structured data as output. Here's an example of the JSON response:
{
"status": "success",
"data": {
"title": "microlink.io",
"description": "Turn websites into data. microlink.io has 34 repositories available. Follow their code on GitHub.",
"lang": "en",
"author": null,
"publisher": "GitHub",
"image": {
"url": "https://avatars0.githubusercontent.com/u/29799436?s=280&v=4",
"type": "png",
"size": 4118,
"height": 280,
"width": 280,
"size_pretty": "4.12 kB"
},
"date": "2020-09-22T09:33:36.000Z",
"url": "https://github.com/microlinkhq",
"logo": {
"url": "https://logo.clearbit.com/github.com",
"type": "png",
"size": 6313,
"height": 128,
"width": 128,
"size_pretty": "6.31 kB"
}
}
}
Example using JavaScript and Axios:
const axios = require('axios');
const url = 'https://microlink.io';
const apiKey = 'YOUR_API_KEY';
/**
* Function to send a GET request to the Microlink API
*/
async function getRequest() {
try {
const options = {
headers: {
Authorization: `Bearer ${apiKey}`,
},
};
const response = await axios.get(`https://api.microlink.io?url=${url}`, options);
console.log(response);
} catch (error) {
console.error(error);
}
}
// Call the getRequest function
getRequest();
This example uses Axios to make a GET request. Remember to replace YOUR_API_KEY
with your actual API key.
Microlink MQL
Microlink also provides MQL (Microlink Query Language), a JavaScript library simplifying API interaction. Here's how to use it:
const mql = require('@microlink/mql');
const { status, data } = await mql('https://github.com/microlinkhq');
mql.render(data);
MQL allows you to pass API parameters as options, offering further customization. For example, you can specify screenshot: true
to include a screenshot in the response. The cache
option (Node.js only) allows leveraging a local cache to reduce API calls. The retry
option controls the number of retries before a request is considered failed. httpOptions
allows passing additional options to the underlying HTTP client (got for Node.js, ky for browser).
Security Considerations
Directly interacting with the Microlink API from the frontend exposes your API key, posing a security risk. Microlink provides a proxy service to mitigate this. This service acts as an intermediary, allowing you to interact with the API without exposing your credentials. You deploy this service and configure it with your API key and allowed origins. Then, you use the proxy's URL instead of the direct API endpoint.
Pricing
Microlink offers a free plan with limitations and paid plans for increased usage and features. Refer to their website for detailed pricing information. https://microlink.io/
React OpenGraph Image Generation: Techniques and Best Practices
Published Jan 15, 2025
Learn how to generate dynamic Open Graph (OG) images using React for improved social media engagement. Explore techniques like browser automation, server-side rendering, and serverless functions....
Setting Up a Robust Supabase Local Development Environment
Published Jan 13, 2025
Learn how to set up a robust Supabase local development environment for efficient software development. This guide covers Docker, CLI, email templates, database migrations, and testing....
Understanding and Implementing Javascript Heap Memory Allocation in Next.js
Published Jan 12, 2025
Learn how to increase Javascript heap memory in Next.js applications to avoid out-of-memory errors. Explore methods, best practices, and configurations for optimal performance....