Extension SDK
Build powerful extensions with the GameCP SDK. Access UI components, APIs, and hooks to create seamless integrations.
Quick Start
npm install @gamecp/types @gamecp/ui
import { useGameCP } from '@gamecp/types/client';
import { Card, Button } from '@gamecp/ui';
useGameCP()
React hook providing access to API client, user data, and utilities for GameCP extensions.
const { api, user, locale, t, getConfig, Link } = useGameCP();
api - HTTP client for external API callsuser - Current authenticated user infolocale - Current user localet() - Translation helpergetConfig() - Access extension configLink - Navigation component@gamecp/ui
React UI component library with 30+ components built with TypeScript and Tailwind CSS.
npm install @gamecp/ui
import { Card, Button, Badge, Modal, DataTable } from '@gamecp/ui';
Core Components: Button, Card, Badge, Modal, Switch, FormInput, LoadingSpinner
Data Display: DataTable, SearchCard, ViewToggle, EmptyState, InfoBox
Layout: Container, Grid, PageHeader, FormSection
Hooks: useConfirmDialog, SmartDropdown, SmartSelect
Loading: Skeleton components for various UI patterns
API Clients
GameCP provides two API clients: external (client-side) and internal (server-side).
External API Client (useGameCP)
Available in UI components via useGameCP().api for making authenticated requests to your extension's backend handlers.
const { api } = useGameCP();
const data = await api.get('/api/x/my-ext/data');
await api.post('/api/x/my-ext/save', { data });
api.get(url) - GET requestsapi.post(url, data) - POST requestsapi.put(url, data) - PUT requestsapi.delete(url) - DELETE requestsapi.fetch(url, options) - Raw fetchInternal API Client (Backend)
Available in backend handlers via ctx.api for making secure internal API calls to GameCP's core systems.
export async function GET(request: Request, ctx: GameCPContext) {
const servers = await ctx.api.get('/api/game-servers');
return Response.json(servers);
}
ctx.api.get(url) - Internal GET requestsctx.api.post(url, data) - Internal POST requestsctx.api.put(url, data) - Internal PUT requestsctx.api.delete(url) - Internal DELETE requestsctx.api.patch(url, data) - Internal PATCH requestsExample Extensions
Complete API Reference
Browse all available functions, types, and interfaces in the GameCP SDK.