Extension SDK

Build powerful extensions with the GameCP SDK. Access UI components, APIs, and hooks to create seamless integrations.

Back to API Reference

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 calls
user - Current authenticated user info
locale - Current user locale
t() - Translation helper
getConfig() - Access extension config
Link - 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 requests
api.post(url, data) - POST requests
api.put(url, data) - PUT requests
api.delete(url) - DELETE requests
api.fetch(url, options) - Raw fetch

Internal 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 requests
ctx.api.post(url, data) - Internal POST requests
ctx.api.put(url, data) - Internal PUT requests
ctx.api.delete(url) - Internal DELETE requests
ctx.api.patch(url, data) - Internal PATCH requests

Complete API Reference

Browse all available functions, types, and interfaces in the GameCP SDK.