{"id":32648243,"url":"https://github.com/schafeld/node-rest-api","last_synced_at":"2026-05-04T00:34:17.062Z","repository":{"id":318932449,"uuid":"1076845105","full_name":"schafeld/node-rest-api","owner":"schafeld","description":"Simple API in Node.js","archived":false,"fork":false,"pushed_at":"2025-10-18T10:02:10.000Z","size":177,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-03-01T22:24:31.758Z","etag":null,"topics":["api","api-rest","bash","javascript","material-ui","netlify","node-js","playwright","rest"],"latest_commit_sha":null,"homepage":"https://schafeld-node-api-items-manager.netlify.app/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/schafeld.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-15T12:28:40.000Z","updated_at":"2025-10-18T10:02:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"14e4c141-6d55-4071-a163-1eb033abd2d2","html_url":"https://github.com/schafeld/node-rest-api","commit_stats":null,"previous_names":["schafeld/node-rest-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/schafeld/node-rest-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schafeld%2Fnode-rest-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schafeld%2Fnode-rest-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schafeld%2Fnode-rest-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schafeld%2Fnode-rest-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schafeld","download_url":"https://codeload.github.com/schafeld/node-rest-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schafeld%2Fnode-rest-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32590392,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T22:12:39.696Z","status":"ssl_error","status_checked_at":"2026-05-03T22:09:10.534Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","api-rest","bash","javascript","material-ui","netlify","node-js","playwright","rest"],"created_at":"2025-10-31T06:01:57.802Z","updated_at":"2026-05-04T00:34:17.046Z","avatar_url":"https://github.com/schafeld.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node.js REST API Demo\n\nA complete REST API backend application demonstrating all HTTP methods (GET, POST, PUT, DELETE, OPTIONS) for managing an items store.\n\n**The [Netlify-version](https://schafeld-node-api-items-manager.netlify.app/) will only use mock data for display. The localhost version is running an actually separate server for the API.**\n\n**TODO:** Attach to separate backend for live API.\n\n## Features\n\n- ✅ **GET** - Retrieve all items or specific item by ID\n- ✅ **POST** - Create new items\n- ✅ **PUT** - Update existing items\n- ✅ **DELETE** - Remove items\n- ✅ **OPTIONS** - CORS preflight support\n- 🌐 CORS enabled for cross-origin requests\n- 📱 HTML interface for browser testing\n- 🔧 JSON API for programmatic access\n- ⚡ In-memory data storage (resets on server restart)\n\n## Getting Started\n\n### Installation \u0026 Running\n\n```bash\n# Navigate to project directory\ncd node-rest-api\n\n# Install dependencies (if any)\nnpm install\n\n# Start the server\nnode server.js\n```\n\nThe server will start on `http://localhost:3000`\n\n### Testing the API\n\n#### Option 1: Browser Interface\nVisit `http://localhost:3000` in your browser to see the HTML interface with all items and API documentation.\n\n#### Option 2: Automated Test Script\n```bash\n# Run the test script (server must be running)\nnode test-endpoints.js\n```\n\n#### Option 3: Manual Testing with curl\n\n## API Endpoints\n\n### 1. GET Methods\n\n#### Get All Items\n```bash\n# HTML response (default)\ncurl http://localhost:3000/\n\n# JSON response\ncurl -H \"Accept: application/json\" http://localhost:3000/items\n```\n\n**Response Example:**\n```json\n{\n  \"message\": \"Items retrieved successfully\",\n  \"count\": 5,\n  \"items\": [\n    {\n      \"id\": 1,\n      \"name\": \"Apple\",\n      \"category\": \"Fruit\",\n      \"price\": 0.5,\n      \"inStock\": true\n    }\n  ]\n}\n```\n\n#### Get Specific Item\n```bash\ncurl http://localhost:3000/items/1\n```\n\n**Response Example:**\n```json\n{\n  \"message\": \"Item retrieved successfully\",\n  \"item\": {\n    \"id\": 1,\n    \"name\": \"Apple\",\n    \"category\": \"Fruit\",\n    \"price\": 0.5,\n    \"inStock\": true\n  }\n}\n```\n\n### 2. POST Method - Create Item\n\n```bash\ncurl -X POST http://localhost:3000/items \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"name\": \"Orange\",\n    \"category\": \"Fruit\", \n    \"price\": 0.8,\n    \"inStock\": true\n  }'\n```\n\n**Required Fields:** `name`, `category`, `price`  \n**Optional Fields:** `inStock` (defaults to `true`)\n\n**Response Example:**\n```json\n{\n  \"message\": \"Item created successfully\",\n  \"item\": {\n    \"id\": 6,\n    \"name\": \"Orange\",\n    \"category\": \"Fruit\",\n    \"price\": 0.8,\n    \"inStock\": true\n  }\n}\n```\n\n### 3. PUT Method - Update Item\n\n```bash\ncurl -X PUT http://localhost:3000/items/1 \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"name\": \"Green Apple\",\n    \"price\": 0.6\n  }'\n```\n\n**Note:** You can update any combination of fields. Omitted fields remain unchanged.\n\n**Response Example:**\n```json\n{\n  \"message\": \"Item updated successfully\",\n  \"item\": {\n    \"id\": 1,\n    \"name\": \"Green Apple\",\n    \"category\": \"Fruit\",\n    \"price\": 0.6,\n    \"inStock\": true\n  }\n}\n```\n\n### 4. DELETE Method - Remove Item\n\n```bash\ncurl -X DELETE http://localhost:3000/items/1\n```\n\n**Response Example:**\n```json\n{\n  \"message\": \"Item deleted successfully\",\n  \"deletedItem\": {\n    \"id\": 1,\n    \"name\": \"Apple\",\n    \"category\": \"Fruit\",\n    \"price\": 0.5,\n    \"inStock\": true\n  }\n}\n```\n\n### 5. OPTIONS Method - CORS Preflight\n\n```bash\ncurl -X OPTIONS http://localhost:3000/items\n```\n\n**Response:** Empty body with CORS headers for cross-origin requests.\n\n## Error Handling\n\nThe API provides comprehensive error responses:\n\n### 400 Bad Request\n```json\n{\n  \"error\": \"Bad Request\",\n  \"message\": \"Missing required fields: name, category, price\",\n  \"required\": [\"name\", \"category\", \"price\"],\n  \"optional\": [\"inStock\"]\n}\n```\n\n### 404 Not Found\n```json\n{\n  \"error\": \"Item not found\", \n  \"message\": \"Item with ID 999 does not exist\"\n}\n```\n\n### 500 Internal Server Error\n```json\n{\n  \"error\": \"Internal Server Error\",\n  \"message\": \"An unexpected error occurred\"\n}\n```\n\n## Data Schema\n\nEach item has the following structure:\n\n```javascript\n{\n  \"id\": number,        // Auto-generated unique identifier\n  \"name\": string,      // Item name (required)\n  \"category\": string,  // Item category (required)  \n  \"price\": number,     // Item price (required)\n  \"inStock\": boolean   // Availability status (optional, defaults to true)\n}\n```\n\n## CORS Support\n\nThe API includes full CORS support with the following headers:\n- `Access-Control-Allow-Origin: *`\n- `Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS`\n- `Access-Control-Allow-Headers: Content-Type, Authorization`\n\n## Demo Application 🏪\n\n### Items Store Manager - Material Design Web Interface\n\nA complete web-based demo application with **Material Design** that provides an intuitive interface for managing items through the REST API. Features professional UI/UX with modern design principles.\n\n**🚀 Quick Start (Local Development):**\n\n```bash\n# Start both API server and demo application\n./start-demo.sh\n\n# Or manually:\nnode server.js    # Terminal 1 - API server (port 3000)\nnode index.js     # Terminal 2 - Demo app (port 8080)\n```\n\n**🌐 Static Deployment (Netlify/Vercel):**\n\n```bash\n# Serve static files (demo mode with mock data)\nnpm run serve\n\n# Deploy to Netlify\nnpm run deploy:netlify\n\n# Deploy to Vercel  \nnpm run deploy:vercel\n```\n\n**Open in browser:** `http://localhost:8080`\n\n### ✨ Material Design Features\n\n- 🎨 **Material Design UI** - Professional design following Google's Material Design principles\n- 📱 **Responsive Interface** - Adaptive layout for desktop, tablet, and mobile\n- 📊 **Statistics Dashboard** - Material Design cards with real-time data\n- ⚡ **Floating Action Button** - Quick access to add new items\n- 🏗️ **Material Components** - Buttons, forms, alerts, and navigation following MD specs\n- 🎭 **Smooth Animations** - Elevation changes, hover effects, and transitions\n- 🌈 **Consistent Theming** - Material Design color palette and typography\n- 📋 **Interactive Lists** - Material Design list styling with icons and actions\n- 🔔 **Snackbar Alerts** - Material Design notification system\n- � **Auto-Detection** - Smart environment detection (development vs production)\n\n### 🚀 Deployment Features\n\n- � **Static Deployment Ready** - Deploy to Netlify, Vercel, GitHub Pages\n- 🔄 **Dual Mode Operation** - API integration + standalone demo mode\n- 🌐 **Progressive Enhancement** - Works offline with mock data\n- ⚙️ **Environment Detection** - Automatic fallback from API to demo mode\n- 🔧 **Easy Configuration** - Simple config for different API endpoints\n\n### Demo Application Architecture\n\n```\nWeb Browser (localhost:8080)\n    ↕ HTTP Requests\nDemo Server (index.js)\n    ↕ Proxy/Static Files\nREST API Server (server.js - localhost:3000)\n    ↕ CRUD Operations\nIn-Memory Data Store\n```\n\n### Available Scripts\n\n```bash\n# Quick start (recommended)\n./start-demo.sh start     # Start both servers\n./start-demo.sh stop      # Stop both servers\n./start-demo.sh status    # Check server status\n./start-demo.sh test      # Run API tests\n./start-demo.sh open      # Open demo in browser\n\n# NPM scripts\nnpm run dev               # Start both servers\nnpm run api              # Start only API server\nnpm run demo             # Start only demo application\nnpm run test-api         # Run automated API tests\nnpm run demo-bash        # Run bash-based API demo\n```\n\n## Project Structure\n\n```\nnode-rest-api/\n├── server.js           # REST API server (port 3000)\n├── index.js            # Demo application server (port 8080)\n├── index.html          # Demo web interface\n├── items.json          # Initial data (5 sample items)\n├── test-endpoints.js   # Automated Node.js test script\n├── demo.sh             # Bash script for API testing\n├── start-demo.sh       # Complete startup script\n├── package.json        # Project metadata with scripts\n└── README.md          # This documentation\n```\n\n## Notes\n\nCheck out this [Coursera short course](https://www.coursera.org/learn/node-js-restful-api-backend-app/ungradedLab/sn2al/apis-in-node-js-write-a-restful-api-backend-app) to learn the basics of Node.js CRUD API apps.\n\n## Future Enhancements\n\n- [ ] Persistent data storage (database integration)\n- [ ] Authentication and authorization\n- [ ] Input validation and sanitization\n- [ ] Rate limiting\n- [ ] API versioning\n- [ ] Logging and monitoring\n- [ ] Import/export data\n\n## TODO\n\n- Should 'in stock' be changed automatically when item count is zero? Or should 'in stock' be renamed to 'available for purchase'?\n- Changing unit numbers is possible inside the list – desirable or not?\n\n## Developer Quick Notes\n\nRunning demo / dev env:\n\n```bash\n# start app and api\nbash start-demo.sh\n\n# check if server/app running\nbash start-demo.sh status\n\n# stop app and api\nbash start-demo.sh stop\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschafeld%2Fnode-rest-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschafeld%2Fnode-rest-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschafeld%2Fnode-rest-api/lists"}