Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpaceX API #414

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions New_APIs/SpaceX API/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 🚀 SpaceX API

## Overview

The **SpaceX API** provides data on SpaceX launches, rockets, capsules, and missions. This API is ideal for space enthusiasts, educational projects, and anyone interested in the latest information on SpaceX's space exploration activities.

## Features

- **Launch Data**: Retrieve details of SpaceX launches, including dates, rockets used, and mission details.
- **Rocket Information**: Get information about SpaceX rockets, including specifications and launch history.
- **Capsule Details**: Access details about SpaceX capsules, including their missions and configurations.
- **Mission Information**: Retrieve data on various missions undertaken by SpaceX.

## Getting Started

### Installation

To use the SpaceX API in a Node.js application, you can use the built-in `fetch` function or any HTTP client library. For simplicity, this example uses `node-fetch`:

```bash
npm install node-fetch
```
## Contributed by
### Revanth
##
23 changes: 23 additions & 0 deletions New_APIs/SpaceX API/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>SpaceX Explorer</title>
</head>
<body>
<header>
<h1>SpaceX Explorer</h1>
</header>
<main>
<section>
<button id="fetchLaunches">Latest Launches</button>
<button id="fetchRockets">Rockets</button>
<button id="fetchMissions">Missions</button>
<div id="dataDisplay"></div>
</section>
</main>
<script src="index.js"></script>
</body>
</html>
41 changes: 41 additions & 0 deletions New_APIs/SpaceX API/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
document.getElementById('fetchLaunches').addEventListener('click', async () => {
await fetchData('/launches');
});

document.getElementById('fetchRockets').addEventListener('click', async () => {
await fetchData('/rockets');
});

document.getElementById('fetchMissions').addEventListener('click', async () => {
await fetchData('/missions');
});

async function fetchData(endpoint) {
try {
const response = await fetch(endpoint);
const data = await response.json();
displayData(data);
} catch (error) {
console.error('Error fetching data:', error);
document.getElementById('dataDisplay').textContent = 'Failed to fetch data.';
}
}

function displayData(data) {
const displayDiv = document.getElementById('dataDisplay');
displayDiv.innerHTML = '';

if (Array.isArray(data)) {
data.forEach(item => {
const itemDiv = document.createElement('div');
itemDiv.classList.add('item');
itemDiv.innerHTML = `
<h3>${item.name || item.mission_name || item.rocket_name}</h3>
<p>${item.details || item.description || item.mission_id}</p>
`;
displayDiv.appendChild(itemDiv);
});
} else {
displayDiv.textContent = 'No data available.';
}
}
19 changes: 19 additions & 0 deletions New_APIs/SpaceX API/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions New_APIs/SpaceX API/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "spacex-explorer",
"version": "1.0.0",
"description": "A simple app to explore SpaceX data using the SpaceX API",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"author": "Your Name",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"node-fetch": "^2.6.1"
}
}

44 changes: 44 additions & 0 deletions New_APIs/SpaceX API/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const express = require('express');
const fetch = require('node-fetch');

const app = express();
app.use(express.static('public'));

const SPACEX_API_BASE_URL = 'https://api.spacexdata.com/v4';

app.get('/launches', async (req, res) => {
try {
const response = await fetch(`${SPACEX_API_BASE_URL}/launches/latest`);
const data = await response.json();
res.json(data);
} catch (error) {
console.error('Error fetching launches:', error);
res.status(500).json({ error: 'Failed to fetch launches' });
}
});

app.get('/rockets', async (req, res) => {
try {
const response = await fetch(`${SPACEX_API_BASE_URL}/rockets`);
const data = await response.json();
res.json(data);
} catch (error) {
console.error('Error fetching rockets:', error);
res.status(500).json({ error: 'Failed to fetch rockets' });
}
});

app.get('/missions', async (req, res) => {
try {
const response = await fetch(`${SPACEX_API_BASE_URL}/missions`);
const data = await response.json();
res.json(data);
} catch (error) {
console.error('Error fetching missions:', error);
res.status(500).json({ error: 'Failed to fetch missions' });
}
});

app.listen(3000, () => {
console.log('Server is running on port 3000');
});
70 changes: 70 additions & 0 deletions New_APIs/SpaceX API/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
margin: 0;
}

header {
text-align: center;
margin-bottom: 20px;
}

header h1 {
font-size: 3em;
color: #fff;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.6);
}

main {
background: rgba(0, 0, 0, 0.6);
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
width: 80%;
max-width: 800px;
text-align: center;
}

button {
padding: 10px 20px;
margin: 10px;
font-size: 1.2em;
color: #fff;
background-color: #333;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}

button:hover {
background-color: #555;
}

#dataDisplay {
margin-top: 20px;
text-align: left;
}

.item {
background: rgba(255, 255, 255, 0.1);
padding: 15px;
margin: 10px 0;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.item h3 {
margin-top: 0;
color: #fdbb2d;
}

.item p {
margin: 5px 0 0;
}