Software Basics • API
API කියන්නේ මොකද්ද?
API (Application Programming Interface) කියන්නේ software systems දෙකකට rules/requests/responses හරහා එකිනෙකා සමඟ වැඩ කරන්න දෙන interface/contract එකක්. User interface එක මිනිසාට; API එක software-to-software interaction එකට.
මේකේ main idea එක
MDN explain කරන විදිහට API එක application එක offer කරන features/rules set එකක්. Web APIs බොහෝවිට HTTP requests use කර JSON data exchange කරනවා. REST කියන්නේ common architectural style/convention family එකක්; every HTTP API strict REST වෙන්නේ නෑ.
Practical checklist
- Endpoint/URL
- HTTP methods: GET, POST, PUT/PATCH, DELETE
- Request parameters/body
- Authentication/API keys/tokens
- Response status + JSON data
- Rate limits
- Errors/retries
- Versioning and documentation
Sri Lanka business එකකට apply කරන්නේ කොහොමද?
Example: website order එක pay කරලා payment gateway callback එක API endpoint එකකට එවීම; website එක SMS provider API එකට OTP request කිරීම; mobile app එක backend API එකෙන් orders load කිරීම.
Step-by-step plan
- Use case define කරන්න
- API docs + auth method read කරන්න
- Sandbox/test credentials use කරන්න
- Error/security/rate-limit handling build කරන්න
- Keys/secrets browser/public code එකේ expose නොකරන්න
Quick Note: API key එක password වගේ secret නම් frontend code/Git repo/public HTML එකේ hard-code කරන්න එපා.