Skip to main content
Glama
wordpress-client.ts1.8 kB
// WordPress API client import axios, { AxiosInstance } from 'axios'; import { Base64 } from 'js-base64'; import { WordPressConfig } from '../config/wordpress-config.js'; import { logger } from '../utils/logger.js'; import { ErrorHandler } from '../utils/error-handler.js'; export class WordPressClient { private axiosInstance: AxiosInstance; private config: WordPressConfig; constructor(config: WordPressConfig) { this.config = config; this.axiosInstance = this.createAxiosInstance(); } private createAxiosInstance(): AxiosInstance { const auth = Base64.encode(`${this.config.username}:${this.config.applicationPassword}`); const baseURL = `${this.config.baseUrl}/wp-json/wp/v2/`; logger.info(`Initializing WordPress client`, { baseUrl: this.config.baseUrl, username: this.config.username, }); const instance = axios.create({ baseURL, headers: { 'Authorization': `Basic ${auth}`, 'Content-Type': 'application/json', }, timeout: 30000, }); // Request interceptor instance.interceptors.request.use( (config) => { logger.request(config.method?.toUpperCase() || 'GET', config.url || ''); return config; }, (error) => { logger.error('Request error', error); return Promise.reject(error); } ); // Response interceptor instance.interceptors.response.use( (response) => { logger.debug(`Response: ${response.status} ${response.statusText}`); return response; }, (error) => { logger.error('Response error', error); return Promise.reject(ErrorHandler.handle(error)); } ); return instance; } getAxiosInstance(): AxiosInstance { return this.axiosInstance; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mbrown1837/Ultimate-Elementor-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server