SDKs overview

PhishStats provides a threat intelligence API that delivers real-time data on phishing URLs, IPs, and domains. Unlike many API providers, PhishStats does not offer official Software Development Kits (SDKs) directly. The API is designed for direct consumption via standard HTTP requests, returning data in JSON format, which allows developers to integrate it using any programming language capable of making web requests. This approach shifts the responsibility of client-side abstraction to the developer or the community.

The absence of official SDKs means that developers typically interact with the PhishStats API by constructing HTTP requests directly to its endpoints. This method requires a clear understanding of the API's request parameters, authentication mechanisms (if any), and response structures, all detailed in the PhishStats API reference documentation. For developers seeking language-specific wrappers, community-contributed libraries often fill this gap, providing a more idiomatic way to interact with the API in various programming environments.

Integrating directly with a RESTful API without an SDK involves several steps, including configuring HTTP clients, handling authentication, managing request parameters, and parsing JSON responses. For instance, a common practice for handling API keys securely involves using environment variables, as recommended by security best practices for application configuration. Developers can consult general guidelines for making HTTP requests with the Fetch API in JavaScript or similar libraries in other languages.

Official SDKs by language

PhishStats does not currently provide any official SDKs or client libraries for its API. Developers integrate with the PhishStats API by sending direct HTTP requests to the specified endpoints and processing the JSON responses. This direct integration method requires developers to manage the HTTP client, request parameters, and response parsing within their application code. The API's design, which emphasizes straightforward JSON over complex data structures, facilitates this direct approach.

While official SDKs are not available, the PhishStats API is well-documented, providing clear examples of request and response formats. This allows developers to build custom API clients in their preferred programming languages. For example, a Python developer might use the requests library, while a Node.js developer might use node-fetch or the built-in http module to interact with the API.

The following table summarizes the status of official SDKs:

Language Package Name Install Command Maturity
Python None N/A N/A (Direct HTTP recommended)
JavaScript/Node.js None N/A N/A (Direct HTTP recommended)
PHP None N/A N/A (Direct HTTP recommended)
Go None N/A N/A (Direct HTTP recommended)
Ruby None N/A N/A (Direct HTTP recommended)

Installation

Given the absence of official PhishStats SDKs, installation primarily involves setting up an HTTP client in your chosen programming language. This section outlines how to prepare your development environment for direct API interaction.

Python

For Python, the requests library is a widely used and recommended HTTP client due to its simplicity and robust features. To install it, use pip:

pip install requests

This command downloads and installs the requests package, enabling your Python applications to send HTTP requests to the PhishStats API. More information on the requests library can be found in its official documentation.

JavaScript/Node.js

In Node.js environments, you can use the built-in http or https modules, or a third-party library like node-fetch or axios. For browser-based applications, the native Fetch API is available.

To install node-fetch (for Node.js environments):

npm install node-fetch

To install axios (for both Node.js and browser environments):

npm install axios

PHP

For PHP projects, Composer is the standard package manager. The Guzzle HTTP client is a popular choice for making HTTP requests.

First, ensure Composer is installed. Then, install Guzzle:

composer require guzzlehttp/guzzle

This command adds Guzzle to your project, allowing you to make HTTP requests to the PhishStats API. Refer to the Guzzle documentation for detailed usage.

Go

Go's standard library includes a robust net/http package for making HTTP requests, so no external installation is strictly required. However, for more complex scenarios or a more ergonomic API, some developers might opt for community libraries. For basic API interaction, the standard library is sufficient.

No specific installation command is needed for the core HTTP client in Go. You simply import the net/http package:

import (
    "net/http"
    "io/ioutil"
)

Quickstart example

This section provides quickstart examples for interacting with the PhishStats API to retrieve phishing data. These examples demonstrate how to fetch the latest phishing URLs using direct HTTP requests, reflecting the primary method of integration due to the absence of official SDKs. Ensure you replace YOUR_API_KEY with your actual PhishStats API key, which is required for authentication and to bypass rate limits beyond the free tier.

Python example

This Python example uses the requests library to fetch the latest phishing URLs from the PhishStats API.

import requests
import json

API_KEY = "YOUR_API_KEY"  # Replace with your PhishStats API key
BASE_URL = "https://phishstats.com/api"

def get_latest_phishing_urls(api_key):
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Accept": "application/json"
    }
    try:
        response = requests.get(f"{BASE_URL}/latest", headers=headers)
        response.raise_for_status()  # Raise an exception for HTTP errors (4xx or 5xx)
        return response.json()
    except requests.exceptions.HTTPError as e:
        print(f"HTTP error occurred: {e}")
        print(f"Response content: {response.text}")
        return None
    except requests.exceptions.RequestException as e:
        print(f"An error occurred during the request: {e}")
        return None

if __name__ == "__main__":
    phishing_data = get_latest_phishing_urls(API_KEY)
    if phishing_data:
        print(json.dumps(phishing_data, indent=2))
        print(f"\nRetrieved {len(phishing_data.get('data', []))} latest phishing URLs.")
    else:
        print("Failed to retrieve phishing data.")

JavaScript (Node.js) example

This Node.js example uses node-fetch to interact with the PhishStats API.

const fetch = require('node-fetch');

const API_KEY = "YOUR_API_KEY"; // Replace with your PhishStats API key
const BASE_URL = "https://phishstats.com/api";

async function getLatestPhishingUrls(apiKey) {
    const headers = {
        "Authorization": `Bearer ${apiKey}`,
        "Accept": "application/json"
    };
    try {
        const response = await fetch(`${BASE_URL}/latest`, {
            method: 'GET',
            headers: headers
        });

        if (!response.ok) {
            const errorText = await response.text();
            throw new Error(`HTTP error! status: ${response.status}, message: ${errorText}`);
        }

        return await response.json();
    } catch (error) {
        console.error("Error fetching phishing data:", error.message);
        return null;
    }
}

(async () => {
    const phishingData = await getLatestPhishingUrls(API_KEY);
    if (phishingData) {
        console.log(JSON.stringify(phishingData, null, 2));
        console.log(`\nRetrieved ${phishingData.data ? phishingData.data.length : 0} latest phishing URLs.`);
    } else {
        console.log("Failed to retrieve phishing data.");
    }
})();

PHP example

This PHP example uses the Guzzle HTTP client to fetch data from the PhishStats API.

<?php

require 'vendor/autoload.php'; // Autoload files using Composer

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;

$apiKey = 'YOUR_API_KEY'; // Replace with your PhishStats API key
$baseUrl = 'https://phishstats.com/api';

function getLatestPhishingUrls($apiKey, $baseUrl)
{
    $client = new Client();
    try {
        $response = $client->request('GET', "{$baseUrl}/latest", [
            'headers' => [
                'Authorization' => "Bearer {$apiKey}",
                'Accept' => 'application/json',
            ],
        ]);

        $statusCode = $response->getStatusCode();
        if ($statusCode === 200) {
            return json_decode($response->getBody()->getContents(), true);
        } else {
            echo "Error: Received status code {$statusCode}\n";
            echo "Response: " . $response->getBody()->getContents() . "\n";
            return null;
        }
    } catch (RequestException $e) {
        echo "Error during request: " . $e->getMessage() . "\n";
        if ($e->hasResponse()) {
            echo "Response: " . $e->getResponse()->getBody()->getContents() . "\n";
        }
        return null;
    }
}

$phishingData = getLatestPhishingUrls($apiKey, $baseUrl);

if ($phishingData) {
    echo json_encode($phishingData, JSON_PRETTY_PRINT) . "\n";
    echo "\nRetrieved " . (isset($phishingData['data']) ? count($phishingData['data']) : 0) . " latest phishing URLs.\n";
} else {
    echo "Failed to retrieve phishing data.\n";
}

?>

Community libraries

While PhishStats does not offer official SDKs, the developer community has created several client libraries to simplify interaction with the API in various programming languages. These libraries often abstract away the complexities of HTTP requests, JSON parsing, and error handling, providing a more convenient and idiomatic interface for developers.

It is important to note that community-contributed libraries are not officially supported or maintained by PhishStats. Developers should review the source code, documentation, and community activity of such libraries before incorporating them into production systems to ensure they meet security, reliability, and functionality requirements. Verification of the library's adherence to the PhishStats API specification is also advised.

Examples of community-driven efforts often include wrappers for popular languages. For instance, on platforms like GitHub, developers might find repositories offering Python client libraries that simplify calls to the /latest or /lookup endpoints, managing API key authentication and response parsing. Similarly, projects for Node.js or Go might exist, leveraging their respective ecosystems for HTTP client management and data serialization.

To find community libraries, developers can search package managers (e.g., PyPI for Python, npm for Node.js, Packagist for PHP) or code hosting platforms (e.g., GitHub) using terms like "PhishStats API" or "PhishStats client." Always prioritize libraries with active maintenance, clear documentation, and a good track record of community contributions and issue resolution.

When evaluating a community library, consider:

  • Last update date: Libraries that are actively maintained are generally more reliable.
  • Documentation quality: Clear examples and API references are crucial for usability.
  • Issue tracker activity: An active issue tracker indicates community engagement and responsiveness to bugs.
  • Security practices: Ensure the library handles API keys and sensitive data securely.

For example, a search on GitHub for "PhishStats Python client" might yield several projects. One such example might be a repository offering a simple Python wrapper that encapsulates API calls, making it easier for Python developers to integrate PhishStats data without writing raw HTTP request logic. While specific libraries are not listed here to avoid endorsement, the principle remains: community contributions can significantly enhance developer experience when official SDKs are absent.