The Airplane API provides CRUD operations for managing airplane data from OpenSky Network. All airplane data is stored in the MySQL database and can be queried, created, updated, and deleted through RESTful endpoints.
http://localhost:8080/api/airplanes
GET /api/airplanes
Returns all airplanes in the database.
Response:
[
{
"id": 1,
"icao24": "a12345",
"callsign": "UAL123",
"originCountry": "United States",
"aircraftType": "Large",
"latitude": 40.6413,
"longitude": -73.7781,
"altitude": 35000,
"groundspeed": 450,
"heading": 90,
"verticalRate": 0.0,
"onGround": false,
"squawk": "1200",
"lastContact": 1707654321,
"createdAt": "2024-02-11T10:00:00",
"updatedAt": "2024-02-11T10:05:00"
}
]GET /api/airplanes/{id}
Returns a specific airplane by its database ID.
GET /api/airplanes/icao24/{icao24}
Returns an airplane by its ICAO24 address (unique identifier).
GET /api/airplanes/callsign/{callsign}
Returns an airplane by its callsign.
GET /api/airplanes/country/{country}
Returns all airplanes from a specific origin country.
GET /api/airplanes/type/{type}
Returns all airplanes of a specific aircraft type.
GET /api/airplanes/ground?status={true|false}
Returns airplanes filtered by ground status.
Parameters:
status(boolean): true for on-ground, false for in-flight
GET /api/airplanes/bounds?minLat={minLat}&maxLat={maxLat}&minLng={minLng}&maxLng={maxLng}
Returns airplanes within a geographic bounding box.
Parameters:
minLat(double): Minimum latitudemaxLat(double): Maximum latitudeminLng(double): Minimum longitudemaxLng(double): Maximum longitude
GET /api/airplanes/recent?timestamp={timestamp}
Returns airplanes that have been contacted after the specified timestamp.
Parameters:
timestamp(long): Unix timestamp in seconds
POST /api/airplanes
Creates a new airplane record.
Request Body:
{
"icao24": "a12345",
"callsign": "UAL123",
"originCountry": "United States",
"aircraftType": "Large",
"latitude": 40.6413,
"longitude": -73.7781,
"altitude": 35000,
"groundspeed": 450,
"heading": 90,
"verticalRate": 0.0,
"onGround": false,
"squawk": "1200",
"lastContact": 1707654321
}POST /api/airplanes/upsert
Creates a new airplane or updates an existing one based on ICAO24 address.
Request Body: Same as Create Airplane
POST /api/airplanes/batch
Creates or updates multiple airplanes in a single request.
Request Body:
[
{
"icao24": "a12345",
"callsign": "UAL123",
...
},
{
"icao24": "b67890",
"callsign": "DAL456",
...
}
]PUT /api/airplanes/{id}
Updates an existing airplane by ID.
Request Body: Same as Create Airplane
DELETE /api/airplanes/{id}
Deletes an airplane by ID.
DELETE /api/airplanes/old?timestamp={timestamp}
Deletes all airplanes with last contact before the specified timestamp.
Parameters:
timestamp(long): Unix timestamp in seconds
CREATE TABLE airplanes (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
icao24 VARCHAR(6) NOT NULL UNIQUE,
callsign VARCHAR(10),
origin_country VARCHAR(100),
aircraft_type VARCHAR(50),
latitude DOUBLE,
longitude DOUBLE,
altitude INT,
groundspeed INT,
heading INT,
vertical_rate DOUBLE,
on_ground BOOLEAN DEFAULT FALSE,
squawk VARCHAR(4),
last_contact BIGINT,
created_at DATETIME NOT NULL,
updated_at DATETIME,
INDEX idx_icao24 (icao24),
INDEX idx_callsign (callsign),
INDEX idx_location (latitude, longitude),
INDEX idx_last_contact (last_contact)
);Use the airplaneapi.js service to interact with the API:
import airplaneAPIService from './services/api/airplaneapi';
// Save OpenSky flights to database
const flights = await openskyapi.getStates(bounds);
await airplaneAPIService.saveOpenSkyFlights(flights.flights);
// Get all airplanes
const airplanes = await airplaneAPIService.getAllAirplanes();
// Get airplanes within bounds
const airplanesInBounds = await airplaneAPIService.getAirplanesWithinBounds(bounds);- Run the database setup script:
mysql -u root -p < backend/database-setup.sql- Start the backend server:
cd backend
mvn spring-boot:run- The API will be available at
http://localhost:8080/api/airplanes