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
Firstly, clone this repository
git clone https://github.com/doannc2212/stub.git
- Run with bun
cd stub
bun install
bun run dev
- Run with Docker
docker compose up -d
Then,
Stub is up on http://localhost:8000
You need to attach cookie userId=${value}
when request for api to know which user need data
- Create a new mock response
Send a request to stub endpoint
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
}
- Clear mock response
POST baseUrl/clear
Cookie: userId=john
- Retrieve mock data
Send request tobaseUrl/api/
+path
which you create before
Request:
GET baseUrl/api/sample
Cookie: userId=john
Response:
{
"id": 1,
"name": "John Doe"
}
The stub API relies on cookies. To resolve this, follow these steps:
- Open Chrome DevTools.
- Navigate to the "Application" tab.
- Locate the cookies associated with your stub API endpoint.
- Set the "Same-Site" attribute of that cookies to "None".