Quick Start
This guide will help you quickly integrate IslamicAPI into your application.
Getting Your API Key
To use IslamicAPI, you'll need an API key. Here's how to get one:
- Sign Up: Create an account at here
- Access Dashboard: Once registered, log in to your dashboard
- Get API Key: Your API key will be displayed in the dashboard
- Update Key: You can regenerate your API key anytime from the dashboard settings
Note: Keep your API key secure and never expose it in client-side code. Always use it from your backend server.
Request Example:
GET
https://islamicapi.com/api/v1/prayer-time/?lat={latitude}&lon={longitude}&method={method}&school={school}&api_key={YOUR_API_KEY}
Code Examples
Here are examples of how to use the IslamicAPI in different programming languages:
cURL
curl -X GET "https://islamicapi.com/api/v1/prayer-time/?lat=51.5194682&lon=-0.1360365&method=3&school=1&api_key=YOUR_API_KEY" \
-H "Accept: application/json"
JavaScript (Fetch API)
const apiKey = 'YOUR_API_KEY';
const lat = '51.5194682';
const lon = '-0.1360365';
const method = '3';
const school = '1';
const url = `https://islamicapi.com/api/v1/prayer-time/?lat=${lat}&lon=${lon}&method=${method}&school=${school}&api_key=${apiKey}`;
fetch(url)
.then(response => response.json())
.then(data => {
console.log('Prayer Times:', data);
if (data.status === 'success') {
console.log('Fajr:', data.data.times.Fajr);
console.log('Dhuhr:', data.data.times.Dhuhr);
console.log('Asr:', data.data.times.Asr);
console.log('Maghrib:', data.data.times.Maghrib);
console.log('Isha:', data.data.times.Isha);
}
})
.catch(error => {
console.error('Error:', error);
});
Python (requests)
import requests
import json
# Your API credentials
api_key = 'YOUR_API_KEY'
lat = '51.5194682'
lon = '-0.1360365'
method = '3'
school = '1'
# API endpoint
url = 'https://islamicapi.com/api/v1/prayer-time/'
# Parameters
params = {
'lat': lat,
'lon': lon,
'method': method,
'school': school,
'api_key': api_key
}
try:
response = requests.get(url, params=params)
response.raise_for_status() # Raises an HTTPError for bad responses
data = response.json()
if data['status'] == 'success':
times = data['data']['times']
print(f"Fajr: {times['Fajr']}")
print(f"Dhuhr: {times['Dhuhr']}")
print(f"Asr: {times['Asr']}")
print(f"Maghrib: {times['Maghrib']}")
print(f"Isha: {times['Isha']}")
else:
print(f"Error: {data.get('message', 'Unknown error')}")
except requests.exceptions.RequestException as e:
print(f"Request failed: {e}")
except json.JSONDecodeError as e:
print(f"JSON decode error: {e}")
PHP
$lat,
'lon' => $lon,
'method' => $method,
'school' => $school,
'api_key' => $apiKey
]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
$data = json_decode($response, true);
if ($data['status'] === 'success') {
$times = $data['data']['times'];
echo "Fajr: " . $times['Fajr'] . "\n";
echo "Dhuhr: " . $times['Dhuhr'] . "\n";
echo "Asr: " . $times['Asr'] . "\n";
echo "Maghrib: " . $times['Maghrib'] . "\n";
echo "Isha: " . $times['Isha'] . "\n";
} else {
echo "Error: " . ($data['message'] ?? 'Unknown error') . "\n";
}
} else {
echo "HTTP Error: " . $httpCode . "\n";
}
?>
Node.js (axios)
const axios = require('axios');
const apiKey = 'YOUR_API_KEY';
const lat = '51.5194682';
const lon = '-0.1360365';
const method = '3';
const school = '1';
const url = 'https://islamicapi.com/api/v1/prayer-time/';
const params = {
lat: lat,
lon: lon,
method: method,
school: school,
api_key: apiKey
};
axios.get(url, { params })
.then(response => {
const data = response.data;
if (data.status === 'success') {
const times = data.data.times;
console.log(`Fajr: ${times.Fajr}`);
console.log(`Dhuhr: ${times.Dhuhr}`);
console.log(`Asr: ${times.Asr}`);
console.log(`Maghrib: ${times.Maghrib}`);
console.log(`Isha: ${times.Isha}`);
} else {
console.error('Error:', data.message || 'Unknown error');
}
})
.catch(error => {
console.error('Request failed:', error.message);
});
Go
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
)
type Response struct {
Code int `json:"code"`
Status string `json:"status"`
Data struct {
Times struct {
Fajr string `json:"Fajr"`
Sunrise string `json:"Sunrise"`
Dhuhr string `json:"Dhuhr"`
Asr string `json:"Asr"`
Sunset string `json:"Sunset"`
Maghrib string `json:"Maghrib"`
Isha string `json:"Isha"`
Imsak string `json:"Imsak"`
Midnight string `json:"Midnight"`
} `json:"times"`
Date struct {
Readable string `json:"readable"`
Timestamp string `json:"timestamp"`
} `json:"date"`
Qibla struct {
Direction struct {
Degrees float64 `json:"degrees"`
From string `json:"from"`
Clockwise bool `json:"clockwise"`
} `json:"direction"`
} `json:"qibla"`
} `json:"data"`
Message string `json:"message,omitempty"`
}
func main() {
// API configuration
apiKey := "YOUR_API_KEY"
lat := "51.5194682"
lon := "-0.1360365"
method := "3"
school := "1"
// Build URL with parameters
baseURL := "https://islamicapi.com/api/v1/prayer-time/"
params := url.Values{}
params.Add("lat", lat)
params.Add("lon", lon)
params.Add("method", method)
params.Add("school", school)
params.Add("api_key", apiKey)
fullURL := baseURL + "?" + params.Encode()
// Make HTTP request
resp, err := http.Get(fullURL)
if err != nil {
fmt.Printf("Error making request: %v\n", err)
return
}
defer resp.Body.Close()
// Read response body
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Printf("Error reading response: %v\n", err)
return
}
// Check HTTP status
if resp.StatusCode != http.StatusOK {
fmt.Printf("HTTP Error: %d\n", resp.StatusCode)
fmt.Printf("Response: %s\n", string(body))
return
}
// Parse JSON response
var apiResponse Response
if err := json.Unmarshal(body, &apiResponse); err != nil {
fmt.Printf("Error parsing JSON: %v\n", err)
return
}
// Handle response
if apiResponse.Status == "success" {
times := apiResponse.Data.Times
fmt.Printf("Prayer Times for %s:\n", apiResponse.Data.Date.Readable)
fmt.Printf("Fajr: %s\n", times.Fajr)
fmt.Printf("Dhuhr: %s\n", times.Dhuhr)
fmt.Printf("Asr: %s\n", times.Asr)
fmt.Printf("Maghrib: %s\n", times.Maghrib)
fmt.Printf("Isha: %s\n", times.Isha)
fmt.Printf("Qibla Direction: %.2f degrees from North\n", apiResponse.Data.Qibla.Direction.Degrees)
} else {
fmt.Printf("API Error: %s\n", apiResponse.Message)
}
}
Java (HttpURLConnection)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import org.json.JSONObject;
public class IslamicAPIExample {
public static void main(String[] args) {
try {
String apiKey = "YOUR_API_KEY";
String lat = "51.5194682";
String lon = "-0.1360365";
String method = "3";
String school = "1";
String urlString = "https://islamicapi.com/api/v1/prayer-time/" +
"?lat=" + URLEncoder.encode(lat, StandardCharsets.UTF_8) +
"&lon=" + URLEncoder.encode(lon, StandardCharsets.UTF_8) +
"&method=" + URLEncoder.encode(method, StandardCharsets.UTF_8) +
"&school=" + URLEncoder.encode(school, StandardCharsets.UTF_8) +
"&api_key=" + URLEncoder.encode(apiKey, StandardCharsets.UTF_8);
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
int responseCode = conn.getResponseCode();
if (responseCode == 200) {
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
JSONObject jsonResponse = new JSONObject(response.toString());
if ("success".equals(jsonResponse.getString("status"))) {
JSONObject times = jsonResponse.getJSONObject("data").getJSONObject("times");
System.out.println("Fajr: " + times.getString("Fajr"));
System.out.println("Dhuhr: " + times.getString("Dhuhr"));
System.out.println("Asr: " + times.getString("Asr"));
System.out.println("Maghrib: " + times.getString("Maghrib"));
System.out.println("Isha: " + times.getString("Isha"));
} else {
System.out.println("Error: " + jsonResponse.optString("message", "Unknown error"));
}
} else {
System.out.println("HTTP Error: " + responseCode);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}