{"id":17932901,"url":"https://github.com/dtinth/mockapis","last_synced_at":"2025-06-23T06:40:37.151Z","repository":{"id":259751426,"uuid":"863939006","full_name":"dtinth/mockapis","owner":"dtinth","description":"Mock API endpoints to make end-to-end testing more convenient","archived":false,"fork":false,"pushed_at":"2025-06-16T09:30:38.000Z","size":156,"stargazers_count":37,"open_issues_count":0,"forks_count":11,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-18T20:49:04.765Z","etag":null,"topics":["elysiajs","hacktoberfest","openapi"],"latest_commit_sha":null,"homepage":"https://mockapis.onrender.com/","language":"TypeScript","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/dtinth.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":"2024-09-27T07:37:58.000Z","updated_at":"2025-06-17T07:26:11.000Z","dependencies_parsed_at":"2024-10-27T20:13:56.439Z","dependency_job_id":"9e765765-9284-427d-9900-82f75bb130aa","html_url":"https://github.com/dtinth/mockapis","commit_stats":null,"previous_names":["dtinth/mockapis"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dtinth/mockapis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtinth%2Fmockapis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtinth%2Fmockapis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtinth%2Fmockapis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtinth%2Fmockapis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dtinth","download_url":"https://codeload.github.com/dtinth/mockapis/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtinth%2Fmockapis/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261430859,"owners_count":23157164,"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":["elysiajs","hacktoberfest","openapi"],"created_at":"2024-10-28T21:34:09.957Z","updated_at":"2025-06-23T06:40:32.110Z","avatar_url":"https://github.com/dtinth.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mock APIs\n\nA collection of mock API endpoints designed to facilitate end-to-end testing development. This project provides a set of simulated APIs that mimic real-world services, allowing developers to test their applications without relying on actual external services.\n\nThe service provides **mock endpoints** and **test endpoints.**\n\n- **Mock endpoints** are endpoints that simulate the behavior of the real service. They should be called from your application code.\n- **Test endpoints** are endpoints that aren’t present in the real service, but are provided here to help you test your application. They should be called from your test code. These endpoint facilitates tasks such as setting up scenarios and verifying the state of the system.\n\nContributions for more APIs are welcome!\n\n## API list\n\n\u003c!-- begin api list --\u003e\n\n\u003c!-- prettier-ignore --\u003e\n| \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;API\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; | Description |\n| --- | --- |\n| [**OAuth 2.0 / OIDC**](https://mockapis.onrender.com/swagger#tag/oauth-20--oidc) | A mock OAuth 2.0 and OpenID Connect provider API that lets users authenticate as anyone they wish. |\n| [**Eventpop**](https://mockapis.onrender.com/swagger#tag/eventpop) | A mock API that implements a subset of the [Eventpop Public API](https://docs.eventpop.me/). |\n| [**GitHub**](https://mockapis.onrender.com/swagger#tag/github) | A mock API that implements a subset of the [GitHub API](https://docs.github.com/en/rest). |\n| [**OpenAI**](https://mockapis.onrender.com/swagger#tag/openai) | A mock API that implements a subset of the [OpenAI API](https://beta.openai.com/docs/api-reference/chat). |\n| [**LINE**](https://mockapis.onrender.com/swagger#tag/line) | A mock API that implements a subset of the [LINE Messaging API](https://developers.line.biz/en/reference/messaging-api/). |\n| [**Vonage**](https://mockapis.onrender.com/swagger#tag/vonage) | A mock API that implements a subset of the [Vonage SMS API](https://developer.vonage.com/en/api/sms) for sending SMS messages. |\n| [**dtinth/kio**](https://mockapis.onrender.com/swagger#tag/dtinthkio) | A mock API that implements the endpoints expected by [dtinth/kio](https://github.com/dtinth/kio), a geeky self-checkin kiosk. |\n| [**OpnPayments**](https://mockapis.onrender.com/swagger#tag/opnpayments) | A mock API that implements a subset of the [OpnPayments API](https://docs.opn.ooo) for receiving payments. |\n| [**SMSKUB**](https://mockapis.onrender.com/swagger#tag/smskub) | A mock API that implements a subset of the [SMSKUB API](https://documenter.getpostman.com/view/9887776/VV4xvFoy#6cfa0c23-5f08-4f80-9e62-ffbf10dd75ea) for sending SMS quick messages. |\n\n\u003c!-- end api list --\u003e\n\n## Example use case\n\nImagine you are developing an application that sends SMS messages through an SMS API provider, and you want to write end-to-end tests your app that verifies the SMS functionality. You can:\n\n1. Configure your application code to send SMS messages through the mock SMS API instead of the real API when certain conditions are met (e.g. when the phone number matches a certain pattern). (Make sure to turn this off in production!)\n2. Write your end-to-end tests, filling in the phone number with a test phone number. This should cause your application to send the SMS through the mock SMS API. Instead of sending a real SMS, the mock SMS API will temporarily store the SMS message in the database.\n3. Call the test endpoint to retrieve the SMS messages sent to the test phone number, and verify that the SMS message was sent correctly.\n\n## Demo\n\nYou can explore the available APIs and their documentation at our demo instance:\n\n\u003chttps://mockapis.onrender.com/\u003e\n\n## Running with Docker\n\n### Using Pre-built Image\n\nFor quick setup without building from source, you can use the pre-built Docker image. Create a `docker-compose.yml` file with the following content:\n\n```yaml\nservices:\n  redis:\n    image: \"redis:latest\"\n  mockapis:\n    image: ghcr.io/dtinth/mockapis:main\n    environment:\n      - REDIS_URL=redis://redis:6379\n    depends_on:\n      - redis\n    ports:\n      - \"46982:46982\"\n```\n\nThen run:\n\n```sh\ndocker compose up -d\n```\n\nThis will start the Mock APIs service using the latest pre-built image from the GitHub Container Registry.\n\n### Building from Source\n\nIf you plan to make changes to the Mock APIs or want to build from source, you can use the `docker-compose.yml` file provided in the repository. Clone the repository and run:\n\n```sh\ndocker compose up -d\n```\n\nThis will build the Docker image from the source code in the repository and start the service.\n\n## Features\n\n- Multiple mock API endpoints simulating various services without the need for authentication or API keys (any key is accepted)\n- CORS support for cross-origin requests\n- Testing endpoints for verifying that your app calls the correct APIs\n\n## Getting Started\n\nTo run the project locally:\n\n1. Clone the repository\n2. Install dependencies with `bun install`\n3. Start the development server with `bun dev`\n\nThe server will start, and you can access the Swagger UI at `http://localhost:46982`.\n\n## Contributing\n\nWe welcome contributions to expand and improve the Mock APIs project! Here are some ways you can contribute:\n\n1. Add new mock API endpoints\n2. Improve existing API simulations\n3. Enhance documentation\n4. Fix bugs or improve performance\n5. Improve test coverage\n\n## Running Tests\n\nTo run the test suite, first run the dev server, and then run the following command:\n\n```bash\nbun generate:types  # Generate types from OpenAPI specs\nbun test            # Run the tests\n```\n\n## Architecture Overview\n\nThe Mock APIs project is built using [Elysia](https://elysiajs.com/), a TypeScript web framework, and uses Redis as an event store. The architecture is designed to be modular and easily extensible.\n\nKey components:\n\n- Elysia for API routing and handling\n- Redis for storing events\n- `EventStore` and `View` utilities for managing state\n- [openapi-typescript](https://openapi-ts.dev/cli) for generating TypeScript types from OpenAPI specs for testing\n- Tester pattern for writing tests\n\n## Adding New APIs\n\nTo add a new API:\n\n1. Create a new file in the `src/apis` directory (e.g., `newapi.ts`).\n2. Define your API using Elysia, including routes and handlers. See existing APIs for examples.\n3. Use the `defineApi` function to export your API:\n4. Import and add your new API to the `apis` array in `src/index.ts`.\n\n## Using EventStore and View\n\nThe `EventStore` and `View` utilities help manage state:\n\n- `EventStore`: Handles storing and retrieving events from Redis.\n- `View`: Helps build a state representation from events.\n\nExample usage:\n\n```typescript\ninterface Events {\n  someEvent: { data: string };\n}\n\nclass MyView extends View\u003cEvents\u003e {\n  someState: string = \"\";\n\n  handleEvent = this.createEventHandler({\n    someEvent: (event) =\u003e {\n      this.someState = event.payload.data;\n    },\n  });\n}\n\n// In your API handler:\nconst eventStore = new EventStore\u003cEvents\u003e(\"my-topic\");\nconst view = new MyView().loadFrom(eventStore);\n```\n\n## Adding Tests\n\nTests are written using Bun's test runner. To add tests for a new API:\n\n1. Create a new test file in the `tests` directory (e.g., `newapi.test.ts`).\n2. Use the tester pattern to create a class that encapsulates API calls.\n3. Write tests using the tester class to interact with your API.\n\n## Tester Pattern\n\nThe tester pattern involves creating a class that wraps API calls and provides methods for interacting with your API. This approach:\n\n- Encapsulates API interaction logic\n- Generates unique identifiers for each test run to keep state isolated\n- Makes tests more readable and maintainable\n- Allows for easy reuse of common API interactions across multiple tests\n\nExample:\n\n```typescript\ntest(\"my api test\", async () =\u003e {\n  const tester = new MyApiTester();\n  await tester.doSomething(\"test\");\n  const state = await tester.getInfo();\n  expect(state).toMatchObject({\n    /* expected state */\n  });\n});\n\nclass MyApiTester {\n  async doSomething(param: string) {\n    const { data } = await api.POST(\"/my/api/endpoint\", {\n      body: { param },\n    });\n    return data;\n  }\n\n  async getInfo() {\n    const { data } = await api.GET(\"/my/api/info\");\n    return data;\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtinth%2Fmockapis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdtinth%2Fmockapis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtinth%2Fmockapis/lists"}