Package Exports
- seo-pilot-client
- seo-pilot-client/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (seo-pilot-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
π SEO Pilot Client
A powerful TypeScript client library for the SEO Pilot API. Effortlessly fetch blog articles, categories, tags, and SEO content with built-in caching and type safety.
β¨ Features
- π₯ TypeScript Support - Full type safety and IntelliSense
- β‘ Built-in Caching - Intelligent caching with configurable TTL
- π Pagination - Easy pagination for articles and content
- π·οΈ Category & Tag Filtering - Filter content by categories and tags
- πΊοΈ Sitemap Generation - Generate SEO-friendly sitemaps
- π Analytics - Get insights with built-in stats
- π Health Monitoring - API health check functionality
- π Modern Fetch API - Built on modern web standards
π¦ Installation
npm install seo-pilot-clientyarn add seo-pilot-clientpnpm add seo-pilot-clientπ Quick Start
import { SeoPilotClient } from 'seo-pilot-client';
// Initialize the client
const client = new SeoPilotClient('your-api-key');
// Fetch the latest articles
const { articles, total } = await client.getPosts(0, 10);
console.log(`Found ${total} articles:`, articles);π API Reference
Constructor
const client = new SeoPilotClient(apiKey: string, baseUrl?: string);apiKey- Your SEO Pilot API keybaseUrl- Optional custom API base URL (defaults tohttps://seo-pilot.ai/api/blog)
Methods
π Articles
// Get paginated articles
const result = await client.getPosts(page: number, limit?: number);
// Get articles by category
const categoryPosts = await client.getCategoryPosts(
slug: string,
page: number,
limit?: number
);
// Get articles by tag
const tagPosts = await client.getTagPosts(
slug: string,
page: number,
limit?: number
);
// Get single article
const article = await client.getPost(slug: string);π·οΈ Categories & Tags
// Get all categories
const categories = await client.getCategories();
// Get all tags
const tags = await client.getTags();π Analytics & SEO
// Get site statistics
const stats = await client.getStats();
// Generate sitemap
const sitemap = await client.getSitemap(baseUrl: string);
// Health check
const health = await client.healthCheck();ποΈ Cache Management
// Clear all caches
client.clearCache();π‘ Usage Examples
Basic Article Fetching
import { SeoPilotClient } from 'seo-pilot-client';
const client = new SeoPilotClient(process.env.SEO_PILOT_API_KEY!);
async function getLatestArticles() {
try {
const { articles, total, pagination } = await client.getPosts(0, 5);
console.log(`π Showing 5 of ${total} articles:`);
articles.forEach(article => {
console.log(`β’ ${article.title} (${article.publishedAt})`);
});
return articles;
} catch (error) {
console.error('β Failed to fetch articles:', error);
}
}Category-Based Content
async function getTechArticles() {
const techPosts = await client.getCategoryPosts('technology', 0, 10);
return techPosts.articles.map(post => ({
title: post.title,
excerpt: post.excerpt,
url: `/blog/${post.slug}`
}));
}SEO Sitemap Generation
async function generateSitemap() {
const sitemap = await client.getSitemap('https://yourdomain.com');
// Use sitemap for SEO optimization
console.log('πΊοΈ Generated sitemap:', sitemap);
return sitemap;
}React Integration Example
import React, { useEffect, useState } from 'react';
import { SeoPilotClient } from 'seo-pilot-client';
const client = new SeoPilotClient(process.env.REACT_APP_SEO_PILOT_KEY!);
function BlogList() {
const [articles, setArticles] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
async function fetchArticles() {
try {
const { articles } = await client.getPosts(0, 10);
setArticles(articles);
} catch (error) {
console.error('Failed to fetch articles:', error);
} finally {
setLoading(false);
}
}
fetchArticles();
}, []);
if (loading) return <div>Loading articles...</div>;
return (
<div>
{articles.map(article => (
<article key={article.slug}>
<h2>{article.title}</h2>
<p>{article.excerpt}</p>
<time>{article.publishedAt}</time>
</article>
))}
</div>
);
}π οΈ Configuration
Custom Cache TTL
// The client uses intelligent caching with a default TTL of 60 seconds
// Caches are automatically managed and cleared when neededError Handling
try {
const articles = await client.getPosts(0, 10);
} catch (error) {
if (error.message.includes('HTTP 401')) {
console.error('Invalid API key');
} else if (error.message.includes('HTTP 429')) {
console.error('Rate limit exceeded');
} else {
console.error('API error:', error.message);
}
}π Requirements
- Node.js 16.0.0 or higher
- TypeScript 4.0+ (for TypeScript projects)
- Valid SEO Pilot API key
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Links
π Support
If you encounter any issues or have questions:
- Check the documentation
- Search existing issues
- Create a new issue if needed
Made with β€οΈ by Edvard Hoilund