
01/07/2025
API ဆိုတာ ဘာလဲ?🤔
API ဆိုတာကို နားလည်အောင် ဥပမာလေးနဲ့ ပြောပြပါမယ်။
* ခင်ဗျားက စားသောက်ဆိုင်တစ်ဆိုင် (ကိုယ့်ရဲ့ Application) ထဲမှာ ရှိနေတယ်လို့ မြင်ယောင်လိုက်ပါ။
* အစားအသောက် (တခြား Application ကနေလိုချင်တဲ့ အချက်အလက် ဒါမှမဟုတ် ဝန်ဆောင်မှု) လိုချင်တယ်။
* ကိုယ်တိုင် မီးဖိုချောင်ထဲဝင်ပြီး အစားအသောက် သွားလုပ်စရာ မလိုဘူး။
* အစားထိုးအနေနဲ့ စားပွဲထိုး (API) ကို ခေါ်ပြောလိုက်တယ်။
* စားပွဲထိုးကို ဘာလိုချင်လဲဆိုတာ (တောင်းဆိုမှု - request လုပ်တာ) ပြောပြတယ်။
* စားပွဲထိုးက မီးဖိုချောင် (တခြား Application/Server) ဆီကို သွားတယ်။
* မီးဖိုချောင်က အစားအသောက်တွေ (တောင်းဆိုမှုကို ဆောင်ရွက်ပေးတာ) ပြင်ဆင်တယ်။
* စားပွဲထိုးက အစားအသောက်တွေ (ပြန်လည်တုံ့ပြန်မှု - response ပြန်တာ) ကို ခင်ဗျားဆီ ယူလာပေးတယ်။
API ရဲ့ အဓိက အချက်တွေကတော့:
* ဆက်သွယ်မှု ပုံစံ/သဘောတူညီချက် (Interface/Contract): API က ဆော့ဖ်ဝဲလ် အစိတ်အပိုင်းနှစ်ခု ဘယ်လို အပြန်အလှန် ဆက်သွယ်ရမယ်ဆိုတာကို သတ်မှတ်ပေးတယ်။ ဒါဟာ ဘယ်လို တောင်းဆိုမှုတွေ လုပ်လို့ရတယ်၊ ဘယ်လို အချက်အလက် ပုံစံမျိုးကို မျှော်လင့်ထားတယ်၊ ဘယ်လို တုံ့ပြန်မှုတွေ ရမယ်ဆိုတာကို သတ်မှတ်ထားတဲ့ သဘောတူညီချက်စာချုပ် တစ်ခုလိုပါပဲ။
* တောင်းဆိုမှုနဲ့ တုံ့ပြန်မှု (Requests and Responses): API တွေဟာ တောင်းဆိုမှု-တုံ့ပြန်မှု ပုံစံနဲ့ အလုပ်လုပ်ပါတယ်။ Application တစ်ခု (သုံးစွဲသူဘက်ခြမ်း - client) က API ကနေတစ်ဆင့် တခြား Application တစ်ခု (ဝန်ဆောင်မှုပေးတဲ့ဘက်ခြမ်း - server) ကို တောင်းဆိုမှု ပို့လိုက်တာနဲ့ Server က အဲ့ဒီတောင်းဆိုမှုကို ဆောင်ရွက်ပြီး ပြန်လည်တုံ့ပြန်မှု ပေးပို့ပါတယ်။
What is API?
(Application Programming Interface)
How it's work?
* You're in a restaurant (your application).
* You want food (data or a service from another application).
* You don't go into the kitchen and make the food yourself.
* Instead, you talk to the waiter (the API).
* You tell the waiter what you want (make a request).
* The waiter goes to the kitchen (the other application/server).
* The kitchen prepares the food (processes the request).
* The waiter brings you the food (sends back a response).
Key aspects of an API:
* Interface/Contract: An API defines how two software components should interact. It's like a contract that specifies what requests can be made, what data formats are expected, and what responses will be given.
* Requests and Responses: APIs operate on a request-response model. One application (the client) sends a request to another application (the server) through the API, and the server processes the request and sends back a response."