Lao Air API Documentation

ຄູ່ມືການນຳໃຊ້ API ສຳລັບລະບົບຈອງປີ້ບິນ Lao Air

ສະຖາບັນ

REST API ແບບມາດຕະຖານ

ຮູບແບບ

JSON Request/Response

ຄວາມປອດໄພ

API Key + Session Auth

ຄວາມຕ້ອງການ

ສຳລັບ Developer

  • ຄວາມຮູ້ພື້ນຖານ REST API
  • JSON ແລະ HTTP Methods
  • PHP, JavaScript, ຫຼື Python
  • ເຄື່ອງມືທົດສອບ API (Postman)

ສຳລັບການຕິດຕັ້ງ

  • Server Linux (CentOS/Ubuntu)
  • AAPanel ຫຼື cPanel
  • PHP 7.4+ ແລະ MySQL 5.7+
  • SSL Certificate

Base URL

https://demo-api.laogair.com/

ນີ້ແມ່ນ URL ຫຼັກທີ່ໃຊ້ສຳລັບການເຂົ້າເຖິງ API ທັງໝົດ

ໝາຍເຫດ:

API ທັງໝົດຕ້ອງໃຊ້ HTTPS ເທົ່ານັ້ນ. HTTP ຈະຖືກ redirect ໄປ HTTPS ອັດຕະໂນມັດ.

ການຢືນຢັນຕົວຕົນ (Authentication)

Session Authentication

ສຳລັບ Web Applications

POST /api/public/auth/login
Content-Type: application/json

{
  "email": "[email protected]",
  "password": "your_password"
}
Response:
{
  "success": true,
  "message": "Login successful",
  "data": {
    "user_id": 123,
    "role": "user"
  }
}

API Key Authentication

ສຳລັບ External Integration

GET /api/api/flights
Authorization: Bearer your-api-key-here
# ຫຼື
X-API-Key: your-api-key-here
Note:

API Key ໃຫ້ຕິດຕໍ່ Admin ເພື່ອຂໍໃຫ້ໃໝ່

ຮູບແບບການຕອບກັບ (Response Format)

Success Response

{
  "success": true,
  "message": "Operation completed successfully",
  "data": {
    // Actual data here
  },
  "timestamp": "2025-01-14T10:30:00+07:00"
}

Paginated Response

{
  "success": true,
  "message": "Data retrieved successfully",
  "data": [
    // Array of items
  ],
  "pagination": {
    "total": 150,
    "page": 1,
    "limit": 20,
    "pages": 8
  },
  "timestamp": "2025-01-14T10:30:00+07:00"
}

Error Response

{
  "success": false,
  "message": "Error message in Lao",
  "errors": {
    "field_name": ["Error details"]
  },
  "timestamp": "2025-01-14T10:30:00+07:00"
}

Public Endpoints

ບໍ່ຕ້ອງການການຢືນຢັນຕົວຕົນ

GET /public/health

ກວດສອບສະຖານະການເຮັດວຽກຂອງ API

Request:

curl -X GET https://demo-api.laogair.com/public/health

Response:

{
  "success": true,
  "message": "API is healthy",
  "data": {
    "status": "online",
    "version": "1.0",
    "uptime": "24 days"
  }
}
GET /public/flights

ດຶງລາຍການຖົບບິນທັງໝົດ (ມີການແບ່ງໜ້າ)

Query Parameters:

Parameter Type Description
page integer ໜ້າທີ່ (default: 1)
limit integer ຈຳນວນຕໍ່ໜ້າ (default: 20, max: 100)
departure_code string ລະຫັດສະໜາມບິນຕົ້ນທາງ (VTE, LPQ, PKZ)
arrival_code string ລະຫັດສະໜາມບິນປາຍທາງ
flight_date date ວັນທີບິນ (YYYY-MM-DD)
curl -X GET "https://demo-api.laogair.com/public/flights?departure_code=VTE&arrival_code=BKK&flight_date=2025-01-20&page=1&limit=10"
POST /public/flights/search

ຄົ້ນຫາຖົບບິນແບບລະອຽດ

Request Body:

{
  "departure_code": "VTE",
  "arrival_code": "BKK",
  "departure_date": "2025-01-20",
  "return_date": "2025-01-25",
  "passengers": 2,
  "class": "economy"
}

Response:

{
  "success": true,
  "message": "Flight search completed successfully",
  "data": {
    "outbound": [
      {
        "id": 1,
        "flight_number": "QV301",
        "departure_time": "08:30",
        "arrival_time": "10:00",
        "price": 1250000,
        "currency": "LAK"
      }
    ],
    "return": []
  }
}

Protected Endpoints

ຕ້ອງການການ Login ກ່ອນ (Session Required)

GET /protected/profile

ດຶງຂໍ້ມູນໂປຣໄຟລ໌ຜູ້ໃຊ້

curl -X GET https://demo-api.laogair.com/protected/profile \
  -H "Cookie: PHPSESSID=your_session_id"
GET /protected/bookings

ດຶງລາຍການການຈອງຂອງຜູ້ໃຊ້

POST /protected/bookings

ສ້າງການຈອງໃໝ່

{
  "flight_id": 1,
  "passenger_name": "ສົມໃສ ວົງໄຊ",
  "passport_number": "N1234567",
  "phone": "+856-20-12345678",
  "email": "[email protected]",
  "seat_class": "economy",
  "special_requests": "vegetarian meal"
}

Admin Endpoints

ຕ້ອງການສິດ Admin (Admin Role Required)

ການຈັດການຖົບບິນ

POST /admin/flights - ສ້າງຖົບບິນໃໝ່
PUT /admin/flights/{id} - ອັບເດດຖົບບິນ
DELETE /admin/flights/{id} - ລຶບຖົບບິນ

ການຈັດການຜູ້ໃຊ້

GET /admin/users - ລາຍການຜູ້ໃຊ້ທັງໝົດ
GET /admin/users/{id} - ຂໍ້ມູນຜູ້ໃຊ້ສະເພາະ
PUT /admin/users/{id} - ອັບເດດຂໍ້ມູນຜູ້ໃຊ້

ການຈັດການຄວາມຜິດພາດ

HTTP Status Codes

Code ຄວາມໝາຍ ການແກ້ໄຂ
200 ສຳເລັດ ບໍ່ຕ້ອງການການແກ້ໄຂ
400 Bad Request - ຂໍ້ມູນບໍ່ຖືກຕ້ອງ ກວດສອບ request body ແລະ parameters
401 Unauthorized - ບໍ່ມີສິດເຂົ້າເຖິງ ລອງອິນກ່ອນ ຫຼື ໃຊ້ API key
403 Forbidden - ຫ້າມເຂົ້າເຖິງ ຕ້ອງການສິດ Admin
404 Not Found - ບໍ່ພົບຂໍ້ມູນ ກວດສອບ URL ແລະ ID
422 Validation Error - ຂໍ້ມູນບໍ່ຖືກຕ້ອງ ແກ້ໄຂຕາມ errors field
429 Rate Limit - ເຮັດ request ຫຼາຍເກີນໄປ ລໍຖ້າຄວາມຊ້າ ແລ້ວລອງໃໝ່
500 Server Error - ຄວາມຜິດພາດຂອງເຊີເວີ ຕິດຕໍ່ Developer

ຕົວຢ່າງ Error Response

{
  "success": false,
  "message": "ຂໍ້ມູນບໍ່ຖືກຕ້ອງ",
  "errors": {
    "departure_code": ["ຕ້ອງເປັນລະຫັດສະໜາມບິນທີ່ຖືກຕ້ອງ"],
    "departure_date": ["ຕ້ອງເປັນວັນທີໃນອະນາຄົດ"]
  },
  "timestamp": "2025-01-14T10:30:00+07:00"
}

Rate Limiting

ຂໍ້ຈຳກັດການໃຊ້ງານ:

  • Public APIs: 100 requests ຕໍ່ຊົ່ວໂມງ ຕໍ່ IP
  • Authenticated APIs: 1000 requests ຕໍ່ຊົ່ວໂມງ ຕໍ່ user
  • Admin APIs: 2000 requests ຕໍ່ຊົ່ວໂມງ

Response Headers

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 85
X-RateLimit-Reset: 1642147200

ກໍລະນີເກີນ Rate Limit

{
  "success": false,
  "message": "Rate limit exceeded",
  "timestamp": "2025-01-14T10:30:00+07:00"
}

ທົດສອບ API

Postman

ເຄື່ອງມືທົດສອບ API ທີ່ນິຍົມ

Download Collection: Postman Collection
Base URL: https://demo-api.laogair.com

cURL Examples

ຄຳສັ່ງ Terminal ສຳລັບທົດສອບ

# Health Check
curl -X GET https://demo-api.laogair.com/public/health

# Search Flights
curl -X POST https://demo-api.laogair.com/public/flights/search \
  -H "Content-Type: application/json" \
  -d '{
    "departure_code": "VTE",
    "arrival_code": "BKK",
    "departure_date": "2025-01-20"
  }'

ທົດສອບ API ໂດຍກົງ

ການຕິດຕັ້ງ AAPanel

ຂັ້ນຕອນການຕິດຕັ້ງ Subdomain:

1. ສ້າງ Subdomain ໃໝ່

  • ເຂົ້າ AAPanel → Website → Add Site
  • Domain Name: demo-api.laogair.com
  • Root Directory: /www/wwwroot/demo.laogair.com/api-docs
  • PHP Version: 7.4 ຫຼື 8.0+

2. ຕິດຕັ້ງ SSL Certificate

  • Website → demo-api.laogair.com → SSL
  • ເລືອກ Let's Encrypt ຫຼື Upload certificate
  • Enable "Force HTTPS"
  • Enable "HSTS" (ແນະນຳ)

3. ກຳນົດ Nginx Configuration

# ເພີ່ມໃນ nginx config
location /api/ {
    try_files $uri $uri/ /api/index.php?$query_string;
}

# API Documentation rewrite
location / {
    try_files $uri $uri/ /index.html;
}

4. ທົດສອບການເຮັດວຽກ

  • ເຂົ້າ https://demo-api.laogair.com
  • ທົດສອບ API: https://demo-api.laogair.com/api/public/health
  • ກວດສອບ SSL ວ່າເຮັດວຽກປົກກະຕິ

DNS Configuration

ເພີ່ມ DNS Record ໃນ Domain Provider:

Type: A
Name: demo-api
Value: YOUR_SERVER_IP
TTL: 300

SDK Examples

JavaScript/Node.js

// Using fetch API
const apiClient = {
  baseURL: 'https://demo-api.laogair.com',
  
  async get(endpoint, params = {}) {
    const url = new URL(endpoint, this.baseURL);
    Object.keys(params).forEach(key => 
      url.searchParams.append(key, params[key])
    );
    
    const response = await fetch(url);
    return response.json();
  },
  
  async post(endpoint, data = {}) {
    const response = await fetch(this.baseURL + endpoint, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(data)
    });
    return response.json();
  }
};

// ຄົ້ນຫາຖົບບິນ
const flights = await apiClient.post('/public/flights/search', {
  departure_code: 'VTE',
  arrival_code: 'BKK',
  departure_date: '2025-01-20'
});

console.log(flights);

PHP

baseURL . $endpoint;
        if (!empty($params)) {
            $url .= '?' . http_build_query($params);
        }
        
        $response = file_get_contents($url);
        return json_decode($response, true);
    }
    
    public function post($endpoint, $data = []) {
        $options = [
            'http' => [
                'header' => "Content-type: application/json\r\n",
                'method' => 'POST',
                'content' => json_encode($data)
            ]
        ];
        
        $context = stream_context_create($options);
        $response = file_get_contents(
            $this->baseURL . $endpoint, 
            false, 
            $context
        );
        
        return json_decode($response, true);
    }
}

// ນຳໃຊ້
$api = new LaoAirAPI();

// ຄົ້ນຫາຖົບບິນ
$flights = $api->post('/public/flights/search', [
    'departure_code' => 'VTE',
    'arrival_code' => 'BKK',
    'departure_date' => '2025-01-20'
]);

print_r($flights);
?>

Python

import requests
import json

class LaoAirAPI:
    def __init__(self):
        self.base_url = 'https://demo-api.laogair.com'
        self.session = requests.Session()
    
    def get(self, endpoint, params=None):
        url = f"{self.base_url}{endpoint}"
        response = self.session.get(url, params=params)
        return response.json()
    
    def post(self, endpoint, data=None):
        url = f"{self.base_url}{endpoint}"
        response = self.session.post(url, json=data)
        return response.json()

# ນຳໃຊ້
api = LaoAirAPI()

# ຄົ້ນຫາຖົບບິນ
flights = api.post('/public/flights/search', {
    'departure_code': 'VTE',
    'arrival_code': 'BKK',
    'departure_date': '2025-01-20'
})

print(json.dumps(flights, indent=2))