Authentication overview
API key भेजने का तरीका चुनें
हर authenticated request के लिए valid GenderAPI key जरूरी है। Authorization header recommended default है क्योंकि यह credentials को request data से अलग रखता है।
Recommended
Authorization header
Authorization: Bearer YOUR_API_KEY set करें और JSON body में केवल input parameters भेजें।
Authorization
Bearer YOUR_API_KEYcURL
curl -X POST "https://api.genderapi.io/api" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"name":"Alice"}'JavaScript
fetch("https://api.genderapi.io/api", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
},
body: JSON.stringify({ name: "Alice" })
});वैकल्पिक तरीका
JSON body में API key
Key को request data के साथ key property में शामिल करें। यह तरीका केवल trusted server-side code से इस्तेमाल करें।
cURL
curl -X POST "https://api.genderapi.io/api" \
-H "Content-Type: application/json" \
-d '{"name":"Alice","key":"YOUR_API_KEY"}'Python
import requests
response = requests.post(
"https://api.genderapi.io/api",
json={
"name": "Alice",
"key": "YOUR_API_KEY"
}
)
print(response.json())Credential safety
अपनी API key सुरक्षित रखें
- Keys को server-side environment variables या secrets manager में store करें।
- Key को source control में commit या browser JavaScript में expose न करें।
- Application, proxy और analytics logs से credentials हटाएँ।
- हर request में HTTPS इस्तेमाल करें और leak की आशंका होने पर key बदलें।
त्वरित तुलना
कौन-सा method इस्तेमाल करें?
| Method | किसके लिए बेहतर | Credential location |
|---|---|---|
| Bearer tokenRecommended | अधिकांश server integrations | Authorization header |
| JSON body | मौजूदा POST integrations | key property |
POST content type: JSON request body भेजते समय
Content-Type: application/json set करें।अगली गाइड