Thuta Learning
ရှာဖွေရန်
AdvancedProgrammingbeginner

REST API Integration

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

REST API Integration Visual Guide
Client → API Server → JSON Response လုပ်ငန်းစဉ်ကို visual guide အနေနဲ့ထည့်ထားပါတယ်။

REST API Integration တွင် RESTful services များနှင့် interact လုပ်ခြင်းဖြစ်သည်။ Real-world applications များတွင် weather data, payment processing, social media integration စသည်တို့အတွက် သုံးသည်။

✨ Best Practices:

• Handle errors properly

• Check status codes

• Use timeouts

• Secure API keys

• Rate limiting awareness

python
# REST API Pattern (Simulated Example)
import json

class WeatherAPI:
    def __init__(self, api_key):
        self.api_key = api_key
        self.base_url = "https://api.weather.com"
    
    def get_weather(self, city):
        # Simulated API response
        weather_data = {
            "city": city,
            "temperature": 32,
            "condition": "Sunny",
            "humidity": 65
        }
        return weather_data

# Using the API
api = WeatherAPI("YOUR_API_KEY_HERE")
weather = api.get_weather("Yangon")

print(f"Weather in {weather['city']}:")
print(f"Temperature: {weather['temperature']}°C")
print(f"Condition: {weather['condition']}")
print(f"Humidity: {weather['humidity']}%")

# Error handling pattern
def safe_api_call(city):
    try:
        result = api.get_weather(city)
        return result
    except Exception as e:
        return {"error": str(e)}

print(f"\nSafe call: {safe_api_call('Mandalay')}")
You should see
Weather in Yangon: Temperature: 32°C Condition: Sunny Humidity: 65% Safe call: {'city': 'Mandalay', 'temperature': 32, 'condition': 'Sunny', 'humidity': 65}
REST API Integration | Thuta Learning