Code Library

You may find api consuming code samples with different programming languages in each API's 'Try it Out/Query' section

PHP Sample Code

	$ch = curl_init();
	$url = 'https://api.turkishairlines.com/test/getPortList';
	$queryParams = '?' . urlencode('airlineCode') . '=' . urlencode('TK') . '&' . urlencode('languageCode') . '=' . urlencode('TR');
	curl_setopt($ch, CURLOPT_URL, $url . $queryParams);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	curl_setopt($ch, CURLOPT_HEADER, FALSE);
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisecret: YOUR API SECRET','apikey: YOUR API KEY'));
	$response = curl_exec($ch);
	curl_close($ch);

	var_dump($response);

Java Sample Code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

public class ApiExplorer {
    public static void main(String[] args) throws IOException {
        StringBuilder urlBuilder = new StringBuilder("https://api.turkishairlines.com/test/getPortList");
        urlBuilder.append("?");
        urlBuilder.append(URLEncoder.encode("airlineCode","UTF-8") + "=" + URLEncoder.encode("TK", "UTF-8") + "&");
        urlBuilder.append(URLEncoder.encode("languageCode","UTF-8") + "=" + URLEncoder.encode("TR", "UTF-8"));
        URL url = new URL(urlBuilder.toString());
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("apisecret", "YOUR API SECRET");
        conn.setRequestProperty("apikey", "YOUR API KEY");
        System.out.println("Response code: " + conn.getResponseCode());
        BufferedReader rd;
        if(conn.getResponseCode() >= 200 && conn.getResponseCode() <= 300) {
            rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        } else {
            rd = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
        }
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = rd.readLine()) != null) {
            sb.append(line);
        }
        rd.close();
        conn.disconnect();
        System.out.println(sb.toString());
    }
}

Javascript Sample Code

var xhr = new XMLHttpRequest();
var url = 'https://api.turkishairlines.com/test/getPortList';
var queryParams = '?' +  encodeURIComponent('airlineCode') + '=' + encodeURIComponent('TK')+ '&' +  encodeURIComponent('languageCode') + '=' + encodeURIComponent('TR');
xhr.open('GET', url + queryParams);
xhr.setRequestHeader('apisecret', 'YOUR API SECRET');
xhr.setRequestHeader('apikey', 'YOUR API KEY');
xhr.onreadystatechange = function () {
    if (this.readyState == 4) {
        alert('Status: '+this.status+'\nHeaders: '+JSON.stringify(this.getAllResponseHeaders())+'\nBody: '+this.responseText);
    }
};

xhr.send('');