API Authentication Methods ## Comparing API Authentication Methods APIs commonly use various authentication methods to secure access. Here's a comparison of three popular methods: | Method | Description | Example Usage | | --- | --- | --- | | **API Key** | A unique identifier passed along with API requests to authenticate the client. | `curl -H "Authorization: ApiKey your_api_key" https://api.example.com/data` | | **OAuth 2.0** | An authorization framework that allows third-party services to exchange web resources on behalf of a user. | `curl -H "Authorization: Bearer your_access_token" https://api.example.com/data` | | **JWT (JSON Web Token)** | A compact, URL-safe means of representing claims to be transferred between two parties. | `curl -H "Authorization: Bearer your_jwt_token" https://api.example.com/data` | Code Samples in Multiple Languages ## Code Sample: Fetching Data from API Here's how you can fetch data from the API using different programming languages: | Language | Code Sample | | --- | --- | | **Python** | ```python import requests response = requests.get('https://api.example.com/data', headers={'Authorization': 'Bearer your_access_token'}) data = response.json() ``` | | **JavaScript (Node.js)** | ```javascript const fetch = require('node-fetch'); fetch('https://api.example.com/data', { method: 'GET', headers: { 'Authorization': 'Bearer your_access_token' } }) .then(response => response.json()) .then(data => console.log(data)); ``` | | **Ruby** | ```ruby require 'net/http' require 'json' uri = URI('https://api.example.com/data') request = Net::HTTP::Get.new(uri) request['Authorization'] = 'Bearer your_access_token' response = Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(request) } data = JSON.parse(response.body) ``` | Nested Tabs Example ## Nested Tabs: Feedback Types Explore different feedback types available: Comment Allows users to leave textual feedback. ```yaml feedback: type: comment settings: label: "Please share your thoughts" submitText: "Submit Feedback" ``` Rating Users can rate content using stars. ```yaml feedback: type: rating settings: label: "Rate this article" submitText: "Submit Rating" ``` Scale Provides a scale for users to express their opinions. ```yaml feedback: type: scale settings: label: "How helpful was this?" submitText: "Submit Response" scale: [1, 2, 3, 4, 5] ```