fshub-api
v4.1.4
Published
TypeScript HTTP API wrapper library for FSHub REST API
Maintainers
Readme
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
- 🚀 Installation
- 📋 Prerequisites
- ⚙️ Configuration
- 🔧 Basic Setup
- 📖 Usage Examples
- 🔍 Data Types
- 🧪 Testing
- 🏗️ Development
- 📚 API Reference
- 🤝 Contributing
- 📄 License
- 🔗 Links
- 🆘 Support
🎯 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');Get All Airline Roles
// Get all Roles
const allRoles = await api.Airline_getAllRoles();Get All Airline Ranks
// Get all Ranks
const allRanks = await api.Airline_getAllRanks();Set Airline Pilot Rank
const rank_id = 6254 // Reef Recruit
const pilot_id = 25097 //NDBoost
const payload: FSHubPilotSetRankData = {
rank_id: rank_id,
};
const response: FSHubApplicationResponse = await api.Airline_pilotSetRank(pilot_id, airline_id, payload);Approve Manual PIREP
const flight_id = 4351163;
const response: FSHubApplicationResponse = await api.Airline_approveManualPIREP(airline_id, flight_id);Reject Manual PIREP
const flight_id = 4351163;
const response: FSHubApplicationResponse = await api.Airline_rejectManualPIREP(airline_id, flight_id);🔍 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 testRun tests in watch mode:
npm run test:watch🏗️ Development
Build
npm run buildLint
npm run lintDevelopment Mode
npm run dev📚 API Reference
Pilot Methods
Pilot_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 Methods
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 statisticsAirline_approveApplication- approve an application to join the airlineAirline_rejectApplication- reject an application to join the airlineAirline_pilotPointPurchase- exchange pilots points for airlineAirline_pilotSetRank- set a pilots rankAirline_getAllRanks- get all airline ranksAirline_getAllRoles- get all airline rolesAirline_approveManualPIREP- approve a member pilot submitted manual PIREPAirline_rejectManualPIREP- reject a member pilot submitted manual PIREP
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
📄 License
ISC License
🔗 Links
🆘 Support
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
