A TypeScript HTTP API wrapper library for the FSHub REST API, providing a clean and type-safe interface for interacting with FSHub's flight simulation community platform.
- π― Purpose
- π Installation
- π Prerequisites
- βοΈ Configuration
- π§ Basic Setup
- π Usage Examples
- π Data Types
- π§ͺ Testing
- ποΈ Development
- π API Reference
- π€ Contributing
- π License
- π Links
- π Support
This library simplifies integration with the FSHub API by providing:
- Type Safety: Full TypeScript support with comprehensive type definitions
- Clean Interface: Simple, intuitive methods for all FSHub API endpoints
- Error Handling: Built-in error handling and response validation
- Modern JavaScript: Built with modern ES modules and async/await patterns
npm install fshub-api- Node.js 18+
- A valid FSHub API key (get one from FSHub)
Optionally. create a .env file in your project root:
FSHUB_API_KEY=your_api_key_hereimport FSHubApi from 'fshub-api';
const api = new FSHubApi({
apiKey: process.env.FSHUB_API_KEY,
// Optional configurations:
baseURL: 'https://fshub.io/api/v3/', // Default
timeout: 10000, // Default: 10 seconds
headers: {} // Additional headers
});const currentPilot = await api.Pilot_getCurrent();
console.log(`Current pilot: ${currentPilot.name} from ${currentPilot.base}`);const allPilots = await api.Pilot_getAll();
console.log(`Total pilots: ${allPilots.length}`);const pilot = await api.Pilot_get(123);
console.log(`Pilot ${pilot.name} is ${pilot.is_online ? 'online' : 'offline'}`);const stats = await api.Pilot_getStats(123);
console.log(`Total flights: ${stats.all_time.total_flights}`);
console.log(`Total hours: ${stats.all_time.total_hours}`);// Get all flights
const allFlights = await api.Pilot_getAllFlights(123);
// Get latest flight
const latestFlight = await api.Pilot_getLatestFlight(123);
// Get flights from specific airport
const departures = await api.Pilot_getAllFlightsDepartures(123, 'KPHX');
const arrivals = await api.Pilot_getAllFlightsArrivals(123, 'KLAX');
// Get flights between specific airports
const routeFlights = await api.Pilot_getAllFlightDeparturesAndArrivals(123, 'KPHX', 'KLAX');const screenshots = await api.Pilot_getAllScreenshots(123);
screenshots.forEach(screenshot => {
console.log(`Screenshot: ${screenshot.name} - ${screenshot.urls.fullsize}`);
});const airlines = await api.Airline_getAll();
console.log(`Total airlines: ${airlines.length}`);const airline = await api.Airline_get(6082);
console.log(`Airline: ${airline.name} (${airline.abbr})`);const pilots = await api.Airline_getPilots(6082);
console.log(`Airline has ${pilots.length} pilots`);const stats = await api.Airline_getStats(6082);
console.log(`Total pilots: ${stats.total_pilots}`);
console.log(`Monthly flights: ${stats.month.total_flights}`);// Get all flights
const allFlights = await api.Airline_getFlights(6082);
// Get flights from specific airport
const departures = await api.Airline_getAllFlightsDepartures(6082, 'KPHX');
const arrivals = await api.Airline_getAllFlightsArrivals(6082, 'KLAX');
// Get flights between specific airports
const routeFlights = await api.Airline_getAllFlightDeparturesAndArrivals(6082, 'KPHX', 'KLAX');The library provides comprehensive TypeScript types for all FSHub data structures:
- Pilot: Pilot information, status, and location
- Flight: Flight details, aircraft, airports, and performance metrics
- Airline: Airline information and ownership details
- PilotStats: Comprehensive pilot statistics (all-time and monthly)
- Screenshot: Pilot screenshot metadata and URLs
- Airport: Airport information with weather and navigation data
Run the test suite:
npm testRun tests in watch mode:
npm run test:watchnpm run buildnpm run lintnpm run devPilot_getCurrent()- Get current authenticated pilotPilot_getAll()- Get all pilotsPilot_get(id)- Get specific pilot by IDPilot_getLatestFlight(id)- Get pilot's latest flightPilot_getAllFlights(id)- Get all pilot flightsPilot_getStats(id)- Get pilot statisticsPilot_getAllFlightsDepartures(id, airportCode)- Get flights departing from airportPilot_getAllFlightsArrivals(id, airportCode)- Get flights arriving at airportPilot_getAllFlightDeparturesAndArrivals(id, departureAirport, arrivalAirport)- Get flights between airportsPilot_getAllScreenshots(id)- Get pilot screenshots
Airline_getAll()- Get all airlinesAirline_get(id)- Get specific airline by IDAirline_getPilots(id)- Get airline pilotsAirline_getPilotStats(id, pilotId)- Get pilot stats within airlineAirline_getFlights(id)- Get airline flightsAirline_getAllFlightsDepartures(id, airportCode)- Get airline flights departing from airportAirline_getAllFlightsArrivals(id, airportCode)- Get airline flights arriving at airportAirline_getAllFlightDeparturesAndArrivals(id, departureAirport, arrivalAirport)- Get airline flights between airportsAirline_getAllScreenshots(id)- Get airline screenshotsAirline_getStats(id)- Get airline statistics
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
ISC License
If you encounter any issues or have questions:
- Check the FSHub API documentation
- Review the test examples in this repository
- Open an issue on GitHub