https://github.com/lmzdev/koa-echo
Koa Middleware for debugging and mockup purposes
https://github.com/lmzdev/koa-echo
koa nodejs npm npm-package typescript
Last synced: 3 months ago
JSON representation
Koa Middleware for debugging and mockup purposes
- Host: GitHub
- URL: https://github.com/lmzdev/koa-echo
- Owner: lmzdev
- License: mit
- Created: 2023-02-27T18:39:19.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-03T08:38:22.000Z (about 2 years ago)
- Last Synced: 2025-02-18T18:47:17.847Z (3 months ago)
- Topics: koa, nodejs, npm, npm-package, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/koa-echo
- Size: 48.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-echo
[](https://github.com/lmzdev/koa-echo/actions/workflows/node.js.yml)Koa Middleware for debugging and mockup purposes.
Mirrors the ```ctx``` Object as response body, including ```ctx.params``` (when used with [@koa/router](https://www.npmjs.com/package/koa-router)), ```ctx.query``` and ```ctx.request.body``` and adds a ```X-Response-Time```-Header.## Installation
```sh
npm install koa-echo
```## Usage
```js
import Koa from 'koa'
import { echo } from 'koa-echo'const app = new Koa()
const port = 3333app
.use(echo())
.use((ctx) => ctx.status = 204)
.listen(port, () => console.log(`Listening on :${port}`))```
## Example Request
```sh
curl --head "localhost:3333" && curl -s "localhost:3333" | jq
``````
HTTP/1.1 200 OK
Content-Type: application/json
Server: node/v18.13.0
X-Response-Time: 0.13ms
Content-Length: 184
Connection: keep-alive
Keep-Alive: timeout=5
``````json
{
"ctx": {
"request": {
"method": "GET",
"url": "/",
"header": {
"host": "localhost:3333",
"user-agent": "curl/7.79.1",
"accept": "*/*"
}
},
"query": {},
"response": {
"status": 204,
"message": "No Content"
}
}
}
```