Skip to content

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.

Notifications You must be signed in to change notification settings

VAMSApp/fshub-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FSHub API

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.

πŸ“‘ Table of Contents

🎯 Purpose

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

πŸš€ Installation

npm install fshub-api

πŸ“‹ Prerequisites

  • Node.js 18+
  • A valid FSHub API key (get one from FSHub)

βš™οΈ Configuration

Optionally. create a .env file in your project root:

FSHUB_API_KEY=your_api_key_here

πŸ”§ Basic Setup

import 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
});

πŸ“– Usage Examples

Pilot Operations

Get Current Pilot

const currentPilot = await api.Pilot_getCurrent();
console.log(`Current pilot: ${currentPilot.name} from ${currentPilot.base}`);

Get All Pilots

const allPilots = await api.Pilot_getAll();
console.log(`Total pilots: ${allPilots.length}`);

Get Specific Pilot

const pilot = await api.Pilot_get(123);
console.log(`Pilot ${pilot.name} is ${pilot.is_online ? 'online' : 'offline'}`);

Get Pilot Statistics

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 Pilot Flights

// 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');

Get Pilot Screenshots

const screenshots = await api.Pilot_getAllScreenshots(123);
screenshots.forEach(screenshot => {
    console.log(`Screenshot: ${screenshot.name} - ${screenshot.urls.fullsize}`);
});

Airline Operations

Get All Airlines

const airlines = await api.Airline_getAll();
console.log(`Total airlines: ${airlines.length}`);

Get Specific Airline

const airline = await api.Airline_get(6082);
console.log(`Airline: ${airline.name} (${airline.abbr})`);

Get Airline Pilots

const pilots = await api.Airline_getPilots(6082);
console.log(`Airline has ${pilots.length} pilots`);

Get Airline Statistics

const stats = await api.Airline_getStats(6082);
console.log(`Total pilots: ${stats.total_pilots}`);
console.log(`Monthly flights: ${stats.month.total_flights}`);

Get Airline 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');

πŸ” Data Types

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

πŸ§ͺ Testing

Run the test suite:

npm test

Run tests in watch mode:

npm run test:watch

πŸ—οΈ Development

Build

npm run build

Lint

npm run lint

Development Mode

npm run dev

πŸ“š API Reference

Pilot Methods

  • Pilot_getCurrent() - Get current authenticated pilot
  • Pilot_getAll() - Get all pilots
  • Pilot_get(id) - Get specific pilot by ID
  • Pilot_getLatestFlight(id) - Get pilot's latest flight
  • Pilot_getAllFlights(id) - Get all pilot flights
  • Pilot_getStats(id) - Get pilot statistics
  • Pilot_getAllFlightsDepartures(id, airportCode) - Get flights departing from airport
  • Pilot_getAllFlightsArrivals(id, airportCode) - Get flights arriving at airport
  • Pilot_getAllFlightDeparturesAndArrivals(id, departureAirport, arrivalAirport) - Get flights between airports
  • Pilot_getAllScreenshots(id) - Get pilot screenshots

Airline Methods

  • Airline_getAll() - Get all airlines
  • Airline_get(id) - Get specific airline by ID
  • Airline_getPilots(id) - Get airline pilots
  • Airline_getPilotStats(id, pilotId) - Get pilot stats within airline
  • Airline_getFlights(id) - Get airline flights
  • Airline_getAllFlightsDepartures(id, airportCode) - Get airline flights departing from airport
  • Airline_getAllFlightsArrivals(id, airportCode) - Get airline flights arriving at airport
  • Airline_getAllFlightDeparturesAndArrivals(id, departureAirport, arrivalAirport) - Get airline flights between airports
  • Airline_getAllScreenshots(id) - Get airline screenshots
  • Airline_getStats(id) - Get airline statistics

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

πŸ“„ License

ISC License

πŸ”— Links

πŸ†˜ Support

If you encounter any issues or have questions:

  1. Check the FSHub API documentation
  2. Review the test examples in this repository
  3. Open an issue on GitHub

About

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.

Resources

Stars

Watchers

Forks

Packages

No packages published