{"id":26380257,"url":"https://github.com/killercavin/library-api","last_synced_at":"2025-03-17T05:19:33.479Z","repository":{"id":277253848,"uuid":"931835608","full_name":"Killercavin/library-api","owner":"Killercavin","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-12T23:49:49.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-13T00:29:35.362Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Killercavin.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}},"created_at":"2025-02-12T23:45:34.000Z","updated_at":"2025-02-12T23:49:52.000Z","dependencies_parsed_at":"2025-02-13T00:39:39.744Z","dependency_job_id":null,"html_url":"https://github.com/Killercavin/library-api","commit_stats":null,"previous_names":["killercavin/library-api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Killercavin%2Flibrary-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Killercavin%2Flibrary-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Killercavin%2Flibrary-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Killercavin%2Flibrary-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Killercavin","download_url":"https://codeload.github.com/Killercavin/library-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243976383,"owners_count":20377691,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-03-17T05:19:32.891Z","updated_at":"2025-03-17T05:19:33.472Z","avatar_url":"https://github.com/Killercavin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📚 Library API  \n\n## 📝 Using MongoDB and Node.js for Developing REST Servicess  \n\n### **📌 Overview**  \nThis project is a **REST API** built using **Node.js, Express, and MongoDB**, allowing users to manage a book collection. It supports **CRUD operations**, including adding books, retrieving available books, updating book availability, and deleting books.  \n\n---\n\n## **🚀 Setup \u0026 Installation**  \nFollow these steps to set up and run the API locally. \n\n### **1️⃣ Unzip the assignment solution file and change directory to the library-api folder**\n``\ncd library-api \n``\n\n### **2️⃣ Install Dependencies**\nRun the following command to install the dependencies required for the project: If you have npm already installed, you can run the following command to install the dependencies required for the project .If not, download and install Node.js from [nodejs.org](https://nodejs.org/en/download/).\n\n``\nnpm install`` or\n``\nnpm i``\n\n### **3️⃣ Set Up MongoDB**\nEnsure you have MongoDB running locally or use a cloud database like MongoDB Atlas. If not download and install MongoDB from [mongodb.com](https://www.mongodb.com/try/download/community) and follow the instructions to set up a local MongoDB instance.\n\n- If using local MongoDB, start it with:\n\n``mongod\n`` or \n``mongod --dbpath /path/to/data/db``\n\n- Update .env with your MongoDB connection string:\n\n``\nMONGO_URI=MONGO_URI=mongodb://localhost:27017/LibraryDB \n``\n\n`` PORT=3000 \n`` \nport from which the server will run at, replace with your favourite port\n\n- Configure the MONGO_URI with your valid MongoDB cluster URI example below if you prefer using MongoDB Cloud Atlas\n\n``MONGO_URI=mongodb+srv://\u003cusername\u003e:\u003cpassword\u003e@libraryapi.tcgai.mongodb.net/?retryWrites=true\u0026w=majority\u0026appName=LibraryAPI\n``\n\n### **4️⃣ Start the Server**\nStart the server\n\n``npm start`` or \n``npm run start``\n\n### **📡 API Endpoints \u0026 Testing**\nUse Postman or cURL to test the API endpoints.\n\n| **Method** | **Endpoint** | **Description** |\n|------------|-------------|----------------|\n| **GET** | `/books` | Fetch all books |\n| **GET** | `/books/available` | Fetch only available books |\n| **POST** | `/books` | Add a new book |\n| **PUT** | `/books/:id/checkout` | Mark a book as checked out |\n| **DELETE** | `/books/:id` | Delete a book |\n\n#### **🧪 Example Requests**\n\n**✅ Fetch All Books**\n\n``curl -X GET http://localhost:3000/books``\n\n**✅ Add a Book**\n\n``curl -X POST http://localhost:3000/books -H \"Content-Type: application/json\" -d '{\n  \"title\": \"The Alchemist\",\n  \"author\": \"Paulo Coelho\",\n  \"ISBN\": \"9780061122415\",\n  \"genre\": \"Adventure\",\n  \"availability\": true\n}'\n``\n\n**✅ Delete a Book**\n\n``curl -X DELETE http://localhost:3000/books/{book_id}\n``\n\n**✅ Update a Book**\n\n``curl -X PUT http://localhost:3000/books/\u003cBOOK_ID\u003e -H \"Content-Type: application/json\" -d '{\n  \"availability\": false\n}'\n``\n\n\n## 📂 Project Structure\n\n```\n📦 library-api\n├── 📁 routes\n│   ├── bookRoutes.js\n├── 📁 models\n│   ├── Book.js\n├── server.js\n├── package.json\n├── .gitignore\n├── .env\n├── pnpm-lock.yaml\n└── README.md\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkillercavin%2Flibrary-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkillercavin%2Flibrary-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkillercavin%2Flibrary-api/lists"}