{"id":30675440,"url":"https://github.com/iamtalwinder/json-server-mock-api","last_synced_at":"2026-06-22T02:31:37.716Z","repository":{"id":208582933,"uuid":"721986770","full_name":"iamtalwinder/json-server-mock-api","owner":"iamtalwinder","description":"A Node.js mock server implementation featuring json-server with integrated JWT-based authentication","archived":false,"fork":false,"pushed_at":"2023-11-23T04:31:13.000Z","size":49,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-01T09:31:24.224Z","etag":null,"topics":["javascript","json-server","mock-api","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iamtalwinder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","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":"2023-11-22T07:41:43.000Z","updated_at":"2023-11-22T16:07:02.000Z","dependencies_parsed_at":"2025-09-01T08:54:23.007Z","dependency_job_id":"cf3a99d2-bf25-43a5-bea4-f9c528366dc6","html_url":"https://github.com/iamtalwinder/json-server-mock-api","commit_stats":null,"previous_names":["iamtalwinder/json-server-mock-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/iamtalwinder/json-server-mock-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamtalwinder%2Fjson-server-mock-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamtalwinder%2Fjson-server-mock-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamtalwinder%2Fjson-server-mock-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamtalwinder%2Fjson-server-mock-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iamtalwinder","download_url":"https://codeload.github.com/iamtalwinder/json-server-mock-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamtalwinder%2Fjson-server-mock-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34632524,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-22T02:00:06.391Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["javascript","json-server","mock-api","nodejs"],"created_at":"2025-09-01T08:54:15.097Z","updated_at":"2026-06-22T02:31:37.698Z","avatar_url":"https://github.com/iamtalwinder.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-server-mock-api\n\n[Blog Post](https://talwinder.tech/blog/building-mock-api-with-json-server)\n\n## Table of Contents\n- [JSON server mock API](#json-server-mock-api)\n    - [Overview](#overview)\n    - [Features](#features)\n    - [Project Structure](#project-structure)\n    - [Prerequisites](#prerequisites)\n    - [Installation](#installation)\n    - [Seeding the Database](#seeding-the-database)\n    - [API Endpoints](#api-endpoints)\n    - [Running with docker](#running-with-docker)\n    - [Contributing](#contributing)\n    - [Contact](#contact)\n\n\n## Overview\n`json-server-mock-api` is a demonstration project that provides a practical example of integrating authentication into a JSON Server mock API. This project not only illustrates how to secure mock API routes but also demonstrates best practices for setting up a mock server and generating dynamic, realistic data using Faker.\n\n## Features\n- **Authentication Integration**: Implement authentication in JSON Server to protect API routes.\n- **Best Practices for Mocking**: Structured approach to setting up a mock API server.\n- **Data Generation with Faker**: Use Faker to generate dynamic, realistic data for the mock API.\n\n\n## Project Structure\n\n```bash\n    src\n      - db\n         -- db.json\n         -- index.js\n         -- seed-data.js\n      - middleware\n         -- authenticate.js\n      - routes\n         -- auth.js\n      - config.js\n      - server.js\n```\n\n**Explanation:**\n\n- **`/src` Directory**: The main source code of the project.\n\n  - **`/db`**: Contains files related to the mock database.\n    - `db.json`: The mock database file, which JSON Server uses to create the API.\n    - `index.js`: Central file for database configurations or exports.\n    - `seed-data.js`: A script to generate and populate `db.json` with dynamic data using Faker.\n\n  - **`/middleware`**: Holds middleware functions.\n    - `authenticate.js`: The authentication middleware to protect certain API routes.\n\n  - **`/routes`**: Contains files defining various API routes.\n    - `auth.js`: Manages authentication-related routes, like login and token validation.\n\n  - `config.js`: A configuration file for the project, possibly including settings like database paths, API keys, or environment-specific configurations.\n\n  - `server.js`: The main server file where JSON Server is configured and started. This file integrates all the routes, middleware, and database configurations.\n\n## Prerequisites\nBefore starting, ensure you have the following installed:\n- Node.js\n- npm\n- docker - if running with docker\n\n## Installation\nTo set up the project on your local machine:\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/iamtalwinder/json-server-mock-api.git\n   ```\n\n2. Change directory to the project folder:\n    ```bash\n    cd json-server-mock-api\n    ```\n\n3. Install the required npm packages:\n    ```bash\n    npm install\n    ```\n\n## Seeding the Database\n\nThe project uses Faker to generate mock data:\n\n1. Run the seeding script to generate `db.json` with fake data:\n    ```bash\n    npm run seed:data\n    ```\n2. Running the Server\n\nTo start the mock API server:\n\n```bash\nnpm start\n```\n\nThe server will run on http://localhost:3000.\n\n## API Endpoints\n\n- /login: For handling authentication requests.\n- /register: For creating user\n\n- Protected routes db.json:\n  - /users: Access user data.\n  - /posts: Retrieve posts data.\n  - /comments: Fetch comments data.\n\n- /protected: A custom route demonstrating protected data access.\n\n## Running with docker\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/iamtalwinder/json-server-mock-api.git\n   ```\n\n2. Change directory to the project folder:\n    ```bash\n    cd json-server-mock-api\n    ```\n\n3. Build the image\n    ```bash\n    docker build -t json-server-mock-api .\n    ```\n\n4. Run project\n    ```bash\n    docker run -p 3000:3000 json-server-mock-api\n    ```\n\n## Contributing\nContributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\n1. Fork the Project\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n## Contact\nTalwinder Singh - [Email](mailto:singhtalwinder790@gmail.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamtalwinder%2Fjson-server-mock-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiamtalwinder%2Fjson-server-mock-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamtalwinder%2Fjson-server-mock-api/lists"}