Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/doannc2212/stub
An application for create custom response
https://github.com/doannc2212/stub
api elysiajs honojs mock redis rest rest-api stub-api testing testing-tools
Last synced: 19 days ago
JSON representation
An application for create custom response
- Host: GitHub
- URL: https://github.com/doannc2212/stub
- Owner: doannc2212
- License: mit
- Created: 2024-01-26T03:41:31.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-12-13T06:25:22.000Z (27 days ago)
- Last Synced: 2024-12-13T07:25:15.378Z (27 days ago)
- Topics: api, elysiajs, honojs, mock, redis, rest, rest-api, stub-api, testing, testing-tools
- Language: TypeScript
- Homepage:
- Size: 90.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stub API
An application for create placeholder implementation of API responses which used as temporary substitute for the actual API.
Build with Hono and redis. Checkout elysia for elysia stuff## Installation
Firstly, clone this repository
```
git clone https://github.com/doannc2212/stub.git
```
1. Run with bun
```
cd stub
bun install
bun run dev
```
2. Run with Docker
```
docker compose up -d
```
Then,
```
Stub is up on http://localhost:8000
```## How to use?
You need to attach cookie `userId=${value}` when request for api to know which user need data1. Create a new mock response
Send a request to stub endpoint
```js
POST baseUrl/create
Cookie: userId=john
{
// request method
"method": "GET",
// requset path, which place right after baseUrl/api/
"path": "/sample",
// response body
"data": {
"id": 1,
"name": "John Doe"
},
// response status
"status": 200
}
```2. Clear mock response
```js
POST baseUrl/clear
Cookie: userId=john
```3. Retrieve mock data
Send request to `baseUrl/api/` + `path` which you create before*Request*:
```js
GET baseUrl/api/sample
Cookie: userId=john
```
Response:
```js
{
"id": 1,
"name": "John Doe"
}
```## FAQ
### Stub api is not work after apply to my web application?
The stub API relies on cookies. To resolve this, follow these steps:
1. Open Chrome DevTools.
2. Navigate to the "Application" tab.
3. Locate the cookies associated with your stub API endpoint.
4. Set the "Same-Site" attribute of that cookies to "None".