Overview
An API for accessing a wealth of information and facts about space.
With SpaceDB, you can effortlessly retrieve data on moons, stars, galaxies, telescopes, spaceships, and more.
Our comprehensive and easy-to-use API allows developers to integrate detailed space data into their applications, making it perfect for educational tools, astronomy apps, research projects, and space enthusiasts.
Features
Our APIs cover a wide variety of space-related topics, including:
- Moons: Access detailed information on various moons, including their characteristics, orbits, and discovery data.
- Stars: Retrieve data on stars, including their classifications, distances, luminosities, and more.
- Galaxies: Get information on different galaxies, such as types, distances, and notable features.
- Telescopes: Learn about different telescopes, including their specifications, locations, and discoveries.
- Spaceships: Obtain data on spaceships, including their missions, specifications, and histories.
Getting Started
1. Log into Your Account
Before accessing the API, you need to log into your SpaceDB account. If you don't have an account yet, sign up on our registration page.
2. Create an App
Once logged in, in the developer section, create a new application. This will generate a unique API key and secret for your app, which you will use to authenticate your requests.
- Go to the "Apps" section.
- Click on "Add new ppp".
- Fill in the required details.
- Click "Save".
3. Get a Bearer Token
To access the SpaceDB API, you need a Bearer Token for authentication. Follow these steps to obtain your Bearer Token:
- Go to the "Apps" section.
- Select the app you created.
- On the Bearer Token, click "Copy".
4. Try Your First Request
Now that you have your Bearer Token, you can make your first API request. Here’s an example using curl to get information about a specific moon:
curl -X GET "https://spacedb.com/api/moons/1" -H
"Authorization: Bearer YOUR_BEARER_TOKEN"
Replace YOUR_BEARER_TOKEN
with the token you generated earlier. This request retrieves data about the moon with ID 1.
Example Response
{
"id": 1,
"name": "Europa",
"parent": "Jupiter",
"discovered_by": "Galileo Galilei",
"discovery_date": "1610-01-08",
"orbital_period_days": 3.55,
"radius_km": 1560.8,
"description": "Europa is the smallest of the four..."
}
Additional Information
- API Documentation: For detailed documentation on all available endpoints and their parameters, visit our API Docs.
- Support: If you need any help, reach out to our support team at support@spacedb.com.
- Community: Join our developer community to connect with other SpaceDB API users, share ideas, and get advice.
Explore the universe with SpaceDB, and integrate the wonders of space into your applications!
Authentication
SpaceDB supports bearer tokens for authenticating your requests.
Obtaining a Bearer Token
To interact with our API securely, you need to obtain a bearer token. This token acts as a key to access protected resources and ensures that only authenticated users can perform certain actions. Below are the steps to create an application, retrieve a bearer token, and use it in your API requests.
To get a bearer token:
- Sign Up/Log In: First, sign up or log in to your developer account on our API platform.
- Create an application: Go to the applications section and create your application.
- Copy your bearer token: In the bearer token section, click to copy your token.
With your bearer token copied, you can now use it to authenticate your API requests. You need to include the token in the Authorization
header of your HTTP requests.
Token Limits
Bearer tokens have specific limitations to be aware of:
- Expiry: Tokens are time-limited and will expire after the period specified in the expires_in field. You must refresh the token or re-authenticate to get a new token.
- Scope: Tokens may have restricted scopes that limit access to certain resources or actions within the API
- Revocation: Bearer tokens cannot be revoked once issued, so it’s crucial to secure them properly.
Security Considerations
To ensure the security of bearer tokens, follow these guidelines:
- Use HTTPS: Always use HTTPS to encrypt the token during transmission and prevent interception by malicious actors.
- Secure Storage: Store tokens securely on the client-side, avoiding insecure methods like local storage. Use secure storage APIs or HttpOnly cookies.
- Token Rotation: Implement token rotation by regularly refreshing tokens to minimize the risk if a token is compromised.
- Scope Limitation: Limit the scope of tokens to the minimum permissions necessary for your application.
- Monitoring: Monitor token usage for unusual activity and implement mechanisms to detect and respond to potential breaches.
- CSRF Protection: Implement Cross-Site Request Forgery (CSRF) protection measures to ensure that requests are made by authenticated users.
Error Handling
When interacting with the API, handle potential token-related errors gracefully:
- 401 Unauthorized: The token is missing or invalid.
- 403 Forbidden: The token does not have the required permissions (scope) to access the resource.
- 400 Bad Request: The request was malformed, often due to invalid parameters or missing required fields.
API Limits
SpaceDB enforces rate limits to ensure fair usage and to prevent abuse.
Understanding Rate Limits
Rate limits define the maximum number of API requests that can be made within a specified time period. This helps to ensure the stability and reliability of the API for all users.
Rate Limit Details
The SpaceDB API offers the following rate limits:
- Standard Users: 100 requests per minute
- Premium Users: 1000 requests per minute
These limits apply to all endpoints within the SpaceDB API.
Handling Rate Limits
When the rate limit is exceeded, the API will return a 429 Too Many Requests
response. The response will include a Retry-After
header indicating the time (in seconds) to wait before making additional requests.
HTTP/1.1 429 Too Many Requests
Content-Type: application/json
Retry-After: 60
{
"error": "Rate limit exceeded. Please wait 60 seconds before retrying."
}
Best Practices
To manage your rate limit effectively, consider the following best practices:
- Implement exponential backoff when retrying requests after hitting rate limits.
- Cache responses whenever possible to reduce the number of API requests.
- Monitor your API usage and adjust your application's behavior based on the current rate limits.
Moons
Requests relating to moon entities.
Get All Moons
Retrieve a list of all moons.
GET /api/moons/all
Response Example:
{
"moons": [
{
"id": 1,
"name": "Europa",
"planet": "Jupiter",
"radius": 1560.8,
"discovered_by": "Galileo Galilei",
"discovery_date": "1610-01-08"
},
...
]
}
Get a Specific Moon
Retrieve details of a specific moon by its ID.
GET /api/moons/{id}
Response Example:
{
"id": 1,
"name": "Europa",
"planet": "Jupiter",
"radius": 1560.8,
"discovered_by": "Galileo Galilei",
"discovery_date": "1610-01-08"
}
Create a New Moon
Add a new moon to the database.
POST /api/moons
Request Body Example:
{
"name": "Titan",
"planet": "Saturn",
"radius": 2574.7,
"discovered_by": "Christiaan Huygens",
"discovery_date": "1655-03-25"
}
Response Example:
{
"id": 4,
"name": "Titan",
"planet": "Saturn",
"radius": 2574.7,
"discovered_by": "Christiaan Huygens",
"discovery_date": "1655-03-25"
}
Update a Moon
Update details of an existing moon by its ID.
PATCH /api/moons/{id}
Request Body Example:
{
"name": "Ganymede",
"planet": "Jupiter",
"radius": 2634.1
}
Response Example:
{
"id": 2,
"name": "Ganymede",
"planet": "Jupiter",
"radius": 2634.1,
"discovered_by": "Galileo Galilei",
"discovery_date": "1610-01-07"
}
Delete a Moon
Remove a moon from the database by its ID.
DELETE /api/moons/{id}
Response Example:
{
"message": "Moon deleted successfully"
}