Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andreyhuey/mock-api
A Node.js-based solution tailored for front-end developers seeking rapid and dependable mock Application Programming Interface (API) services. Designed to bridge the gap between UI development and back-end readiness.
https://github.com/andreyhuey/mock-api
fakerjs fs json-schema json-schema-faker json-server node
Last synced: 10 days ago
JSON representation
A Node.js-based solution tailored for front-end developers seeking rapid and dependable mock Application Programming Interface (API) services. Designed to bridge the gap between UI development and back-end readiness.
- Host: GitHub
- URL: https://github.com/andreyhuey/mock-api
- Owner: Andreyhuey
- License: mit
- Created: 2024-03-21T18:21:36.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-06-02T20:02:03.000Z (7 months ago)
- Last Synced: 2024-10-31T03:42:11.134Z (about 2 months ago)
- Topics: fakerjs, fs, json-schema, json-schema-faker, json-server, node
- Language: JavaScript
- Homepage:
- Size: 846 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Mock API
## Introduction
This project serves as a robust solution for front-end developers in need of quick and reliable mock API services. Born from the necessity to bridge the gap between UI development and back-end readiness, it utilizes the strengths of [faker-js](https://fakerjs.dev/guide/localization.html#available-locales), [json-schema](https://json-schema.org/learn/getting-started-step-by-step), [json-schema-faker](https://www.npmjs.com/package/json-schema-faker), and [json-server](https://www.npmjs.com/package/json-server) to fabricate precise and versatile JSON data. Whether you're crafting a dynamic interface or testing feature completeness, this tool ensures your development never skips a beat.
## Motivation
The struggle to acquire mock testing data is a common pain point for software developers. This project arose from a real-world experience where a lack of readily available backend APIs stalled progress on a freelance project. Existing tools like faker-js provided realistic data generation, but integrating them with data validation and server capabilities required additional effort.
This Mock API project tackles this challenge head-on by offering a seamless solution. It combines the power of:
- **faker-js**: Generates realistic and diverse data sets.
- **json-schema**: Defines the structure and data types for your mock data.
- **json-schema-faker**: Creates JSON data that adheres to your defined schema.
- **json-server**: Provides a lightweight server to host your mock data, enabling easy CRUD (Create, Read, Update, Delete) operations.This user-friendly solution empowers developers to quickly generate and serve customized mock APIs, significantly boosting development efficiency and facilitating robust testing practices.
## Requirements, Example, Installation, Configuration, Execution, Results & Tests
### Requirements
You need the following below to run this on your pc, so please ensure to download
- Node.js 18.0.0 or higher
- Git### Example
A practical & indepth example of how to write your own mock api [Example.md](/Example.md)
### Installation
Embark on your journey with our mock API by following these beginner-friendly instructions:
1. Clone this repository to your local machine.
2. Navigate to the project's root directory.
3. Execute the code below in your terminal to install all necessary dependencies.```sh
npm install json-server json-schema-faker
``````sh
npm install --save-dev @faker-js/faker fs jest
```Congratulations, you're all set to generate your custom JSON data!
### Configuration
Our project structure is designed for simplicity and efficiency:
- **`/src/schema/`**: This directory houses your JSON schemas. Here, you define the structure, types, and volume of your desired mock data.
- **`/src/generators/`**: This area is reserved for the json-schema-faker configurations. Utilize our provided templates or craft your own to generate the necessary JSON files.### Execution
To breathe life into your mock API, follow these steps:
1. Open the `package.json` file and scroll to the `"scripts"` section.
2. Customize the following scripts:
- **`generate-mock-data`**: Specify the path to your json-schema-faker generator file.
- **`prestart-mockapi`**: This script generates the JSON data file.
- **`start-mockapi`**: Define the path to the generated JSON data and the port for your mock server.
3. Launch your mock API with:
```sh
npm run start-mockapi
```### Results
- **`/dist/`**: This directory contains all the JSON data generated through the execution process. It serves as the repository for your mock data, ready for use.
- Ports: The generated JSON data is hosted on a specified port. This setup allows for direct CRUD (Create, Read, Update, Delete) operations from your localhost, facilitating seamless integration and testing within your development environment.### Tests
![](./src/assets/json-server-test.png)
Jest testing framework was utilized to thoroughly evaluate the functionalities of the json-server. The tests successfully validated GET, PUT, and DELETE operations.
## Performance and Scalability
This Mock API tool has undergone rigorous testing to ensure its ability to handle extensive data generation with ease. It boasts the capability of generating up to 1,000,000 precise and versatile JSON data entries, making it an ideal solution for demanding testing scenarios that require significant data volumes. This performance benchmark reflects the commitment to supporting developers with robust data simulation capabilities, guaranteeing reliable and efficient operation even under challenging conditions.
## How to contribute and ask questions
### Contribute
Your contributions are highly valued! Whether it's improving the documentation, adding new features, or fixing bugs, your help can make a significant difference. Here's how to get started:
1. **Fork the repository**: Start by forking the repository to your GitHub account. This step creates your own copy of the project, allowing you to freely experiment with changes.
2. **Make your changes**: Work on your forked version of the project. Whether it’s a small typo fix or a major addition, your contributions are welcome.
3. **Submit a pull request (PR)**: Once you're satisfied with your changes, submit a pull request. In your PR, clearly describe the changes you've made and the impact they have on the project.Your submission will be reviewed as soon as possible. If your changes align with the project’s goals and quality standards, they will be merged into the main branch.
Looking forward to your creative and insightful contributions!
### Questions?
Curious about something concerning this project and want to clear things up? Please send me an [email](mailto:[email protected]), or feel free to open an issue in the project's GitHub issue tracker for more detailed questions or suggestions.
project stars are greately appreciated :)