Skip to main content

TypeScript Client

Official TypeScript SDK for Carapis API with modern ES6+ features and full type safety.

📦 Download

📦 Download TypeScript Client

Extract the archive and include the generated client files in your TypeScript/JavaScript project.

Quick Start

import { createClient } from './encar_public/client';
import { dataEncarApiVehiclesWebList, dataEncarApiVehiclesWebRetrieve } from './encar_public';

// Create API client
const api = createClient({
baseUrl: 'https://api.carapis.com',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json',
},
});

// List vehicles
const list = await dataEncarApiVehiclesWebList({ client: api, query: { page: 1, page_size: 10 } });

// Get vehicle details
const detail = await dataEncarApiVehiclesWebRetrieve({ client: api, path: { listing_id: '12345' } });

console.log(list.data.results);
console.log(detail.data);

API Examples

List Vehicles

import { createClient } from './encar_public/client';
import { dataEncarApiVehiclesWebList } from './encar_public';

const apiKey = process.env.CARAPIS_API_KEY || 'your-api-key';
const api = createClient({
baseUrl: 'https://api.carapis.com',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json',
},
});

const response = await dataEncarApiVehiclesWebList({
client: api,
query: {
page_size: 10,
page: 1,
ordering: '-created_at',
},
});

console.log('Total vehicles:', response.data.count);
response.data.results.forEach((v) => {
console.log(`${v.brand?.name} ${v.vehicle_model?.name} (${v.year})`);
});

Get Single Vehicle

import { createClient } from './encar_public/client';
import { dataEncarApiVehiclesWebRetrieve } from './encar_public';

const apiKey = process.env.CARAPIS_API_KEY || 'your-api-key';
const api = createClient({
baseUrl: 'https://api.carapis.com',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json',
},
});

const vehicle = await dataEncarApiVehiclesWebRetrieve({
client: api,
path: { listing_id: '12345' },
});
console.log(vehicle.data);

Error Handling

import { createClient } from './encar_public/client';
import { dataEncarApiVehiclesWebList } from './encar_public';

const apiKey = process.env.CARAPIS_API_KEY || 'your-api-key';
const api = createClient({
baseUrl: 'https://api.carapis.com',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json',
},
});

try {
const response = await dataEncarApiVehiclesWebList({
client: api,
query: { page_size: 5 },
});
console.log(response.data.results);
} catch (error) {
console.error('API error:', error);
}

React Integration

Basic React Hook

import { useEffect, useState } from 'react';
import { createClient } from './encar_public/client';
import { dataEncarApiVehiclesWebList } from './encar_public';

const apiKey = process.env.CARAPIS_API_KEY || 'your-api-key';
const api = createClient({
baseUrl: 'https://api.carapis.com',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json',
},
});

function VehicleList() {
const [vehicles, setVehicles] = useState([]);
const [loading, setLoading] = useState(true);

useEffect(() => {
dataEncarApiVehiclesWebList({
client: api,
query: { page_size: 10, page: 1 },
})
.then((response) => setVehicles(response.data.results))
.catch(console.error)
.finally(() => setLoading(false));
}, []);

if (loading) return <div>Loading...</div>;
return (
<ul>
{vehicles.map((v) => (
<li key={v.listing_id}>
{v.brand?.name} {v.vehicle_model?.name} ({v.year})
</li>
))}
</ul>
);
}

Features

  • Full TypeScript support
  • Browser & Node.js compatible
  • Modern ES6+ syntax
  • Auto-generated from OpenAPI
  • Zero-dependency design
  • Type-safe API calls

Environment Variables

# .env.local
CARAPIS_API_KEY=your-api-key-here
import { createClient } from './encar_public/client';

const apiKey = process.env.CARAPIS_API_KEY;
if (!apiKey) {
throw new Error('CARAPIS_API_KEY is required');
}

const api = createClient({
baseUrl: 'https://api.carapis.com',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json',
},
});

Support

License

Part of the Carapis ecosystem. See LICENSE for details.