https://github.com/basia1111/simple-rest-api
https://github.com/basia1111/simple-rest-api
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/basia1111/simple-rest-api
- Owner: basia1111
- Created: 2024-10-21T14:46:13.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-10-21T15:04:56.000Z (8 months ago)
- Last Synced: 2025-01-19T16:28:10.828Z (5 months ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Product API
## Description
This is a simple RESTful API for managing products, built with Express.js and MongoDB. It provides basic CRUD operations.
## Features
- CRUD operations for products
- Input validation
- Error handling## Technologies Used
- **Node.js**
- **Express.js**
- **MongoDB**
- **Mongoose**
- **dotenv**## Installation
1. Clone the repository:
```bash
git clone https://github.com/yourusername/product-api.git
```2. Navigate to the project directory:
```bash
cd product-api
```3. Install dependencies:
```bash
npm install
```4. Create a `.env` file and add your MongoDB connection string:
```plaintext
DATABASE_URL=mongodb://localhost:27017/yourdbname
```## Usage
1. Start the server:
```bash
npm start
```The server will run on `http://localhost:3000`.
## API Endpoints
### Get All Products
- **Endpoint**: `GET /products`
- **Response**: List of all products.### Get a Product by ID
- **Endpoint**: `GET /products/:id`
- **Response**: Details of the specified product.### Create a New Product
- **Endpoint**: `POST /products`
- **Request Body**:
```json
{
"name": "Product Name",
"price": 19.99,
"inStock": true
}
```
- **Response**: Confirmation message with the created product.### Update a Product
- **Endpoint**: `PUT /products/:id`
- **Request Body**:
```json
{
"name": "Updated Product",
"price": 25.99,
"inStock": false
}
```
- **Response**: Confirmation message with the updated product.### Delete a Product
- **Endpoint**: `DELETE /products/:id`
- **Response**: Confirmation message.