screenshotlayer-node
v0.0.3
Published
screenshotlayer api wrapper
Downloads
12
Maintainers
Readme
screenshotlayer-node (Screenshotlayer Node Rest API)
This API supported Screenshotlayer standard REST API that accepts/returns JSON requests. Here is the API reference
You can find examples of JavaScript and TypeScript. This will help you for faster implementation of Screenshotlayer APIs.
It does supports EcmaScript 5, EcmaScript 6, EcmaScript 8, TypeScript, async-await, Promises, Callback!!!
It does also supports for AWS Lambda like serverless cloud function call.
It supports pure JSON response.
A method support Promise and Callback both.
Please Feel free to create issue for any help!
All developers/contributors are requested to open Pull Request/Merge Request on develop branch.
Please make sure Test Cases be passed.
Get started
Using the Screenshotlayer API wrapper for Node.js is really simple.
Given that you already have a Node.js project with NPM setup just follow these steps:
Installation
npm install screenshotlayer-node --save
Pull Request
- Contributors can send their Pull Request to
develop
branch. - Kindly validate test cases & linting before opening new PR.
Do you need an expert?
Are you finding a developer or team for your world-class enterprise product development? If yes, please send email to. Submit your project request here. Originally by Vijay Patoliya.
Configuration Using JavaScript
export SSLAYER_CLIENT_ACCESS_KEY=API_ACCESS_KEY
var screenshotlayer = require('screenshotlayer-node')('YOUR_ACCESS_KEY');
Configuration Using TypeScript
import * as ScreenShotLayerAPI from 'screenshotlayer-node';
const sslayer = new ScreenShotLayerAPI();
sslayer.setApiKey('YOUR_ACCESS_KEY');
Originally by Vijay Patoliya ([email protected]).
Example
Capture a snapshot
sslayer.setApiKey(clientAccessKey);
var data = {
url: 'https://www.google.com'
};
try {
var response = sslayer.application.captureSnapshot(data);
} catch (error) {
return;
}
following code define how to save image file using above response data
var pathToSave = 'path/to/save';
var imageName = 'image';
var extension = response.imageType;
var fileName = pathToSave + '/' + imageName + '.' + extension;
var wstream = fs.createWriteStream(fileName);
var bufferString = Buffer.from(JSON.parse(response.imageBufferData).data);
wstream.write(bufferString);
wstream.on('error', (err) => {
console.log(err);
wstream.end();
});
console.log('created image: ', fileName);