API কী — পরিচিতি ও প্রকারভেদ

লেসন ৩৩ / ৩৯

API কী?

API (Application Programming Interface) — দুটি সফটওয়্যার-এর মধ্যে যোগাযোগের ইন্টারফেস।

রেস্টুরেন্ট analogy

আপনি (Client) → Order → Waiter (API) → Kitchen (Server)
                          ↑                    │
                          └──── Food ──────────┘

Waiter একটি API — client সরাসরি রান্নাঘরে যায় না।

API কোথায়?

  • Mobile App ↔ Server (Facebook, WhatsApp)
  • Frontend ↔ Backend (React + PHP)
  • Third-party — Google Maps, Payment gateway, SMS
  • Microservices

Architecture Styles

REST ⭐

  • HTTP methods (GET, POST, PUT, DELETE)
  • Resource-based URL (/users)
  • Stateless
  • JSON response

SOAP

  • পুরনো, XML ভিত্তিক
  • Enterprise, ভারী

GraphQL

  • Facebook, আধুনিক
  • Client বলে কী ডেটা দরকার
  • একটি endpoint

REST Principles

  1. Client-Server আলাদা
  2. Stateless
  3. Cacheable
  4. Uniform Interface
  5. Layered

Public vs Private API

  • Public — যে কেউ (Twitter)
  • Partner — অনুমোদিত
  • Private — ভিতরের

উদাহরণ

GET https://api.github.com/users/torvalds

Response:
{
    "login": "torvalds",
    "name": "Linus Torvalds",
    "public_repos": 7
}

সুবিধা

  • Frontend/Backend আলাদাভাবে
  • Mobile, Web — একই backend
  • Third-party integration
  • Reusable