0.1.0 • Published 10 months ago
@peekalink/core v0.1.0
@peekalink/core
Core Peekalink API client for JavaScript. Can be used anywhere JavaScript runs. Fully type-safe and easy to use!
Getting Started
1. Install the package:
pnpm install @peekalink/core2. Instantiate a Peekalink API client:
import { PeekalinkClient } from "@peekalink/core";
const peekalink = new PeekalinkClient({
apiKey: "your-api-key",
});3. Preview a link:
const preview = await peekalink.preview("https://youtu.be/QB7ACr7pUuE");
if (preview.type === "YOUTUBE_VIDEO") {
console.log(preview.youtubeVideo);
}Customizing options
You can either customize each request individually by passing an options object
as the second argument to the preview method:
const preview = await peekalink.preview("https://youtu.be/QB7ACr7pUuE", {
source: "WEB",
});...or you can set default options for all requests:
const peekalink = new PeekalinkClient({
apiKey: "your-api-key",
defaultOptions: {
source: "WEB",
},
});See more about the available options.
Customizing fetch options
If you'd like to customize the fetch request options (e.g. headers, timeout,
proxy, etc.), you can do so by passing a third parameter to the preview
method:
const preview = await peekalink.preview("https://youtu.be/QB7ACr7pUuE", undefined, {
// ... custom fetch options
});Customizing the endpoint
For things such as mocking unit tests, you can customize the endpoint that the
client will make calls to by passing an endpoint option to the client's
constructor:
const peekalink = new PeekalinkClient({
apiKey: "your-api-key",
endpoint: "https://peekalink.test",
});License
MIT.
0.1.0
10 months ago