Authentication overview

Launch Library 2, developed by The Space Devs, provides programmatic access to space launch data, including details on upcoming and past launches, vehicles, missions, and agencies. To ensure proper resource allocation and prevent abuse, access to the API is managed through an authentication system that primarily utilizes API keys. These keys identify the client making the request and are subject to usage limits, such as the free tier's 500 requests per hour (Launch Library 2 API documentation). While some public endpoints may allow unauthenticated access for specific queries, authenticated requests provide consistent access within the defined rate limits and are generally recommended for reliable integration.

The API key serves as a unique identifier for your application. When an API key is included in a request, the Launch Library 2 system can track usage, enforce rate limits, and, if necessary, identify and block malicious activity. This mechanism is common in public APIs designed for broad developer access while maintaining service stability. Understanding how to securely obtain, store, and transmit your API key is crucial for building robust and reliable applications that interact with Launch Library 2.

Supported authentication methods

Launch Library 2 primarily supports API key authentication. This method involves generating a unique key from your user account and including it in your API requests. The API key acts as a simple credential that grants access to the API's resources up to your allocated rate limit.

The table below summarizes the supported authentication method:

Method When to Use Security Level
API Key When making server-side requests or client-side requests where the key can be securely managed (e.g., proxied through a backend). Suitable for most applications requiring access to Launch Library 2 data. Moderate: Relies on the secrecy of the key. Less secure if exposed in client-side code directly.

API keys are generally suitable for applications that do not require user-specific authentication or advanced authorization flows like OAuth 2.0. They are straightforward to implement and manage, making them a practical choice for many data consumption APIs. For more information on API key security, consult resources like the Google Cloud API Keys documentation, which provides guidance on best practices for protecting API keys in various environments.

Getting your credentials

To obtain an API key for Launch Library 2, you must first register for an account on The Space Devs website. The process typically involves a few steps:

  1. Visit The Space Devs Website: Navigate to the official website for The Space Devs, which hosts the Launch Library 2 API (The Space Devs homepage).
  2. Register for an Account: Look for a "Register" or "Sign Up" link. You will likely need to provide an email address, create a username, and set a password. Confirm your email address if required.
  3. Access Your Dashboard/Profile: Once registered and logged in, locate your user dashboard or profile settings.
  4. Generate API Key: Within your dashboard, there should be an option to generate a new API key. This process typically creates a unique string of characters that serves as your credential. Copy and store this key securely immediately after generation.

It is critical to treat your API key as sensitive information. Do not embed it directly into publicly accessible client-side code (e.g., JavaScript in a static web page) or commit it to public version control systems. If your API key is compromised, it could lead to unauthorized API usage against your account's quota, and potentially lead to your key being revoked.

Authenticated request example

Once you have obtained your API key, you can include it in your API requests to Launch Library 2. The API key is typically passed as a query parameter named key in the request URL. Below are examples demonstrating how to make an authenticated request using common programming languages and tools.

Curl Example

This Curl example retrieves a list of upcoming launches, including your API key as a query parameter:

curl -X GET "https://ll.thespacedevs.com/2.2.0/launch/upcoming/?key=YOUR_API_KEY"

Replace YOUR_API_KEY with the actual API key you obtained from The Space Devs dashboard.

Python Example

This Python example uses the requests library to fetch data on upcoming launches:

import requests
import os

API_KEY = os.environ.get("LAUNCH_LIBRARY_API_KEY")
BASE_URL = "https://ll.thespacedevs.com/2.2.0"

if API_KEY:
    params = {
        "key": API_KEY
    }
    response = requests.get(f"{BASE_URL}/launch/upcoming/", params=params)

    if response.status_code == 200:
        data = response.json()
        print(data)
    else:
        print(f"Error: {response.status_code} - {response.text}")
else:
    print("API_KEY environment variable not set.")

This example demonstrates retrieving the API key from an environment variable, which is a recommended security practice for server-side applications.

JavaScript (Node.js) Example

This Node.js example uses the node-fetch library to make an authenticated request:

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

const API_KEY = process.env.LAUNCH_LIBRARY_API_KEY;
const BASE_URL = "https://ll.thespacedevs.com/2.2.0";

async function getUpcomingLaunches() {
    if (!API_KEY) {
        console.error("LAUNCH_LIBRARY_API_KEY environment variable not set.");
        return;
    }

    const url = `${BASE_URL}/launch/upcoming/?key=${API_KEY}`;

    try {
        const response = await fetch(url);
        if (response.ok) {
            const data = await response.json();
            console.log(data);
        } else {
            console.error(`Error: ${response.status} - ${response.statusText}`);
        }
    } catch (error) {
        console.error("Failed to fetch upcoming launches:", error);
    }
}

getUpcomingLaunches();

Similar to the Python example, the JavaScript code fetches the API key from an environment variable, improving security by not hardcoding the key.

Security best practices

Securing your API key is paramount to maintaining the integrity and availability of your application's access to Launch Library 2. Adhering to these best practices will help prevent unauthorized use and potential disruptions:

  • Never Hardcode API Keys: Avoid embedding your API key directly into your application's source code, especially for client-side applications (e.g., web browsers, mobile apps). Hardcoded keys are easily extracted and can be abused.

  • Use Environment Variables or Configuration Management: For server-side applications, store API keys in environment variables, secure configuration files, or dedicated secrets management services. This keeps keys out of your codebase and allows for easier rotation and management. For example, AWS Secrets Manager (AWS Secrets Manager overview) or Google Secret Manager (Google Cloud Secret Manager documentation) provide secure ways to handle sensitive credentials.

  • Proxy Client-Side Requests: If your application is client-side (e.g., a single-page application in a browser), route all API requests through your own backend server. The backend server can then securely add the API key before forwarding the request to Launch Library 2. This prevents direct exposure of the key to end-users.

  • Implement Rate Limiting and Monitoring: Even with an API key, implement your own rate limiting and monitoring on your application's side. This can help detect unusual activity or potential key compromise early. Monitor your usage statistics on The Space Devs dashboard to identify unexpected spikes.

  • Regularly Rotate API Keys: Periodically generate new API keys and invalidate old ones. This practice minimizes the window of opportunity for a compromised key to be exploited. While Launch Library 2's documentation doesn't specify a key rotation frequency, a common practice is quarterly or annually.

  • Restrict Key Usage (if applicable): While Launch Library 2 API keys are generally broad, if future versions or other APIs offer IP address restrictions or referer restrictions, enable them. This adds an extra layer of security by limiting where and by whom the key can be used.

  • Secure Your Development Environment: Ensure that your development machines and build pipelines are secure. Avoid storing API keys in plain text on local drives or in insecure development environments.

  • Use HTTPS: Always transmit API keys over HTTPS (HTTP Secure) to encrypt the communication between your application and the Launch Library 2 API. This protects the key from being intercepted by attackers during transit. Launch Library 2 endpoints are served exclusively over HTTPS.