API Concepts:
API (Application Programming Interface) enables software communication without
exposing internal logic.
Types of APIs:
1. Web APIs: Communicate over HTTP.
2. Application APIs: Facilitate communication between applications.
3. Device APIs: Interface with hardware devices.
4. Database APIs: Interact with databases.
Common API Protocols:
1. SOAP: XML-based protocol for exchanging structured data.
2. REST: Uses HTTP methods for CRUD operations.
3. JSON-RPC: Lightweight remote procedure call protocol using JSON.
4. gRPC: Uses HTTP/2 for fast communication.
5. GraphQL: Enables clients to request specific data.
REST API Key Features:
1. Stateless: Each request from a client contains all necessary information.
2. Layered System: Architecture divided into layers for scalability.
3. Uniform Interface: Standardized way of interacting with resources.
4. Supports Caching: Improves performance by storing responses.
HTTP Methods:
1. GET: Retrieve data
2. POST: Create new resource
3. PUT/PATCH: Update existing resource
4. DELETE: Remove resource
5. OPTIONS/HEAD: Fetch supported methods or headers
API Security and Status Codes
1. Authentication vs. Authorization:
1. Authentication: Verifying user identity.
a. Methods: API Keys, OAuth 2.0, JWT (JSON Web Token)
2. Authorization: Determining permissions after authentication.
a. Roles: Admin, User, Guest
2. HTTP Status Codes in REST APIs:
Success (2xx):
1. 200 OK: Request succeeded
2. 201 Created: Resource created successfully
3. 204 No Content: Successful operation, no content to return
Client Errors (4xx):
1. 400 Bad Request: Invalid syntax or request
2. 401 Unauthorized: Authentication required
3. 403 Forbidden: Access denied
4. 404 Not Found: Resource not found
Server Errors (5xx):
1. 500 Internal Server Error: Generic server failure
2. 503 Service Unavailable: Server temporarily unavailable