Answer
Overview
API stands for Application Programming Interface — a set of rules and protocols that allows one software application to communicate with another.
Full Form
textAPI = Application Programming Interface
Types of APIs
1. REST API (Representational State Transfer)
Most common type — uses HTTP methods over the web.
dart// REST API in Flutter final response = await http.get( Uri.parse('https://api.example.com/users'), headers: {'Authorization': 'Bearer $token'}, );
| Method | Operation |
|---|---|
| GET | Read data |
| POST | Create data |
| PUT/PATCH | Update data |
| DELETE | Delete data |
2. GraphQL API
Query-based API — request exactly the data you need.
graphql# Single query gets nested data query { user(id: "1") { name email orders { id, total } } }
3. gRPC API (Google Remote Procedure Call)
Binary protocol using Protocol Buffers — high performance.
protobufservice UserService { rpc GetUser (UserRequest) returns (UserResponse); rpc ListUsers (Empty) returns (stream UserResponse); }
4. WebSocket API
Persistent bidirectional real-time communication.
dartfinal channel = WebSocketChannel.connect(Uri.parse('wss://api.example.com/ws')); channel.stream.listen((message) => print(message)); channel.sink.add('Hello');
5. SOAP API (Simple Object Access Protocol)
XML-based, enterprise legacy systems.
xml<soap:Envelope> <soap:Body> <GetUser><userId>1</userId></GetUser> </soap:Body> </soap:Envelope>
6. Webhook API
HTTP callback — server pushes data to your endpoint.
textPayment complete → Stripe POSTs to your /webhook endpoint
7. Library/SDK API
APIs within a programming language (not over network).
dart// Flutter's own API Text('Hello') // Using Flutter widget API SharedPreferences.getInstance() // Plugin API
API Comparison
| Type | Protocol | Format | Use Case |
|---|---|---|---|
| REST | HTTP | JSON | General web APIs |
| GraphQL | HTTP | JSON | Flexible data fetching |
| gRPC | HTTP/2 | Protobuf | Microservices, high perf |
| WebSocket | TCP | Any | Real-time (chat, games) |
| SOAP | HTTP | XML | Legacy enterprise |
| Webhook | HTTP | JSON | Event notifications |
Summary: API is the contract between two systems. REST is the most common for mobile apps. gRPC for performance-critical services. WebSocket for real-time. GraphQL for flexible queries.