API Dökümantasyon
Temel Kullanım
Cinsiyet sorgulama için tek yapmanız gereken aşağıdaki adrese sorgu göndermek. Bütün sorgularınızın sonucu JSON verisi olarak geri döner.
İstek
GET https://genderapi.io/api/?name=abraham&key=<YourAPIKey>
Alan | Veri Tipi | Açıklama |
---|---|---|
name | String | Sorgulayacağınız isim |
key | String | API anahtarınız |
POST https://genderapi.io/api/?key=<YourAPIKey>&name=abraham
Alan | Veri Tipi | Açıklama |
---|---|---|
name | String | Sorgulayacağınız ismi POST parametresi olarak göndermeniz gerekmektedir |
key | String | API anahtarınız |
Yanıt
{
"name":"abraham",
"q":"abraham",
"gender":"male",
"total_names":1173,
"country":"MX",
"probability":99,
"status":true,
"duration":"106ms",
"used_credits":1,
"remaining_credits":472,
"expires":1523404800,
"server":"genderapi.io/api"
}
Alan | Veri Tipi | Açıklama |
---|---|---|
name | String | Sorgulanan isim |
q | String | Gönderilen isim dizisi |
gender | String | Olası değerler: male, female, null |
total_names | Integer | İsteğinize uyan kayıtların veritabanımızdaki sayısı. |
country | String | En çok kullanılan ülke kodu |
probability | String | Bu değer veritabanımızın doğruluğunu belirler. 100 değeri, cinsiyet sorgunuzdaki sonuçların %100 doğru olduğu anlamına gelir. |
status | Boolean | Yaptığınız isteğinizin sonucu (true ya da false) |
duration | String | İsteğinizin sunucuda işlenme süresi. |
used_credits | Integer | Bu istekte kullanılan kredi sayısı |
remaining_credits | Integer | Paketinizde kalan kredi sayısı |
expires | Timestamp | Paketinizin son kullanma tarihi |
server | String | İsteğinize yanıt veren sunucu |
Temel Kurulum
Entegrasyon için temel örnek kodlar.
<?php
function findGender($name) {
$apiKey = ''; //Your API Key
$getGender = json_decode(file_get_contents('https://genderapi.io/api/?key=' . $apiKey . '&name=' . urlencode($name)));
return $getGender->gender;
}
echo findGender('angela');
Composer command
$ composer require genderapi/php-client
<?php
use GenderApi\GenderApi;
$genderApi = new GenderApi('Your API Key');
$getGender = $genderApi->findGender('britney');
echo $getGender;
// OR, Get Result
$getResult = $genderApi->result('britney');
print_r($getResult);
Python 3.*
import json
from urllib.request import urlopen
apiKey = "" #Your API Key
apiUrl = "https://genderapi.io/api/?name=georgi&key=" + apiKey
result = urlopen(apiUrl).read().decode('utf-8')
getGender = json.loads(result)
print( "Gender: " + getGender["gender"]);
Python 2.*
import json
import urllib2
apiKey = "" #Your API Key
apiUrl = "https://genderapi.io/api/?name=irina&key=" + apiKey
getGender = json.load(urllib2.urlopen(apiUrl))
print "Gender: " + getGender["gender"];
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.HttpURLConnection;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
public class Main {
public static void main(String[] args) {
try {
String apiKey = ""; //Your API Key
URL apiUrl = new URL("https://genderapi.io/api/?name=elvan&key=" + apiKey);
HttpURLConnection connect = (HttpURLConnection) apiUrl.openConnection();
if (connect.getResponseCode() != 200) {
throw new RuntimeException("An server error: " + connect.getResponseCode());
}
InputStreamReader iStream = new InputStreamReader(connect.getInputStream());
BufferedReader bReader = new BufferedReader(iStream);
Gson gson = new Gson();
JsonObject jsonOb = gson.fromJson(bReader, JsonObject.class);
String result = jsonOb.get("gender").getAsString();
System.out.println("Gender: " + result); // Gender: male
connect.disconnect();
} catch (IOException error) {
error.printStackTrace();
}
}
}
Javascript & jQuery Example
<!-- Add Javascript & jQuery Library your project -->
<script src="https://genderapi.io/assets/cdn/genderapi.min.js"></script>
//Javascript Code
let API_KEY = ""; //Your API Key
genderApi(API_KEY,"honor",function(result){
console.log(result);
});
//jQuery Code
let API_KEY = ""; //Your API Key
$.genderApi(API_KEY,"honor",function(result){
console.log(result);
});
Javascript Callback Example
<html>
<head>
<meta charset="utf-8">
<title>GenderAPI.io - Javascript Callback Example</title>
</head>
<body>
<input readonly id="result"/>
<script>
function genderApiResult(result) {
var gender = document.getElementById('result');
if (result.gender) {
gender.value = result.gender;
} else {
gender.value = result.errmsg
}
}
</script>
<!-- Add Javascript Callback Library your project -->
<!-- Add your API key -->
<script src="//genderapi.io/api/?name=anna&callback=genderApiResult&key="></script>
</body>