This repository contains a RESTful API server designed to manage and modify constellation data. It is part of educational exercises used in Thinkful's Flex and Immersive Web Development programs. The server enables CRUD operations (Create, Read, Update, Delete) for constellation records and can be used to practice building and interacting with APIs.
The Constellations Server provides an API that allows users to interact with a dataset of constellations, performing operations such as fetching a list of constellations, creating new constellations, updating existing ones, and deleting records. This project serves as a hands-on learning tool for working with APIs in a Node.js environment.
Before starting, ensure that you have the following installed:
- Node.js (version 12.x or later)
- npm (version 6.x or later)
To verify the installation of Node.js and npm, run the following commands in your terminal:
node -v
npm -v
If the commands do not return version numbers, please refer to Node.js installation guide for assistance.
To get started with the project, follow these steps:
-
Fork this repository by clicking the "Fork" button at the top right of this page.
-
Clone the repository to your local machine:
git clone https://github.com/Thinkful-Ed/starter-constellations-server.git
-
Navigate into the project directory:
cd starter-constellations-server
-
Install the project dependencies:
npm install
-
Start the server:
npm start
By default, the server will run on http://localhost:5001.
The Constellations Server exposes several API endpoints for interacting with constellation data.
Fetches an array of all constellation objects.
Example Request:
GET http://localhost:5001/constellations
Example Response:
[
{
"id": "UEUrlfX",
"name": "Columba",
"meaning": "Dove",
"starsWithPlanets": 3,
"quadrant": "SQ1"
},
{
"id": "zb8QvVt",
"name": "Crater",
"meaning": "Cup",
"starsWithPlanets": 10,
"quadrant": "SQ2"
}
]
Fetches a specific constellation by its ID.
Example Request:
GET http://localhost:5001/constellations/UEUrlfX
Example Response:
{
"id": "UEUrlfX",
"name": "Columba",
"meaning": "Dove",
"starsWithPlanets": 3,
"quadrant": "SQ1"
}
Creates a new constellation record. The request body should include information about the constellation.
Example Request:
POST http://localhost:5001/constellations
{
"name": "Camelopardalis",
"meaning": "Giraffe",
"starsWithPlanets": 7,
"quadrant": "SQ1"
}
Example Response:
{
"id": "IVU9de",
"name": "Camelopardalis",
"meaning": "Giraffe",
"starsWithPlanets": 7,
"quadrant": "SQ1"
}
Updates an existing constellation by ID. Include the updated information in the request body.
Example Request:
PUT http://localhost:5001/constellations/IVU9de
{
"name": "Camelopardalis",
"meaning": "Giraffe",
"starsWithPlanets": 7,
"quadrant": "NQ2"
}
Example Response:
{
"id": "IVU9de",
"name": "Camelopardalis",
"meaning": "Giraffe",
"starsWithPlanets": 7,
"quadrant": "NQ2"
}
Deletes a constellation by ID.
Example Request:
DELETE http://localhost:5001/constellations/IVU9de
Example Response:
{}
-
The data you modify during testing is stored in a
db.json
file. If you want to reset the data to its initial state, use the following command:git checkout db.json
This will restore the data to its original state.
- Port Conflicts: If you encounter a port conflict (another service is using port 5001), you can either stop the conflicting service or change the port number in the server settings.
- Node.js Version Issues: Ensure that you are running Node.js version 12.x or higher.