Skip to content

Commit 24ea979

Browse files
committed
initial commit
1 parent f7d4a79 commit 24ea979

File tree

5 files changed

+388
-2
lines changed

5 files changed

+388
-2
lines changed

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:18-alpine
2+
RUN apk add --no-cache tini
3+
4+
RUN mkdir /app
5+
WORKDIR /app
6+
7+
COPY package.json .
8+
COPY index.js .
9+
10+
RUN npm install --production
11+
12+
ENTRYPOINT ["/sbin/tini", "--"]
13+
CMD ["node", "index.js"]

README.md

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,57 @@
1-
# echo-api
2-
Basic Echo API to help debugging API gateway solutions and introduce artificial latency
1+
# Introduction
2+
Basic *echo* API to help debugging API gateway or proxy solutions.
3+
4+
# Usage
5+
The service exposes the following endpoints:
6+
- `GET /echo/:latency/ms`: The endpoints respond with the HTTP request headers using the `:latency` parameter value to introduce artificial latency.
7+
8+
## Example:
9+
```bash
10+
docker run --rm -p 3000:3000 kyberneees/echo-api:latest
11+
```
12+
```bash
13+
curl -v http://localhost:3000/echo/10/ms
14+
15+
* Trying 127.0.0.1:3000...
16+
* Connected to localhost (127.0.0.1) port 3000 (#0)
17+
> GET /echo/10/ms HTTP/1.1
18+
> Host: localhost:3000
19+
> User-Agent: curl/7.79.1
20+
> Accept: */*
21+
>
22+
* Mark bundle as not supporting multiuse
23+
< HTTP/1.1 200 OK
24+
< x-added-latency-ms: 10
25+
< content-type: application/json; charset=utf-8
26+
< Date: Wed, 25 May 2022 12:50:24 GMT
27+
< Connection: keep-alive
28+
< Keep-Alive: timeout=5
29+
< Content-Length: 67
30+
<
31+
* Connection #0 to host localhost left intact
32+
{"host":"localhost:3000","user-agent":"curl/7.79.1","accept":"*/*"}
33+
```
34+
35+
Container logs:
36+
```bash
37+
GET /echo/10/ms 200 - - 10.244 ms
38+
...
39+
```
40+
41+
# Implementation
42+
```js
43+
const restana = require('restana')
44+
const morgan = require('morgan')
45+
46+
const service = restana()
47+
service.use(morgan('tiny'))
48+
49+
service.get('/echo/:latency/ms', (req, res) => {
50+
const { latency } = req.params
51+
52+
res.setHeader('x-added-latency-ms', latency)
53+
setTimeout(() => res.send(req.headers), latency)
54+
})
55+
56+
service.start(3000)
57+
```

index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const restana = require('restana')
2+
const morgan = require('morgan')
3+
4+
const service = restana()
5+
service.use(morgan('tiny'))
6+
7+
service.get('/echo/:latency/ms', (req, res) => {
8+
const { latency } = req.params
9+
10+
res.setHeader('x-added-latency-ms', latency)
11+
setTimeout(() => res.send(req.headers), latency)
12+
})
13+
14+
service.start(3000)

package-lock.json

Lines changed: 275 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "echo-api",
3+
"version": "1.0.0",
4+
"description": "Basic Echo API to help debugging API gateway solutions and introduce artificial latency",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/BackendStack21/echo-api.git"
12+
},
13+
"keywords": [
14+
"echo",
15+
"api",
16+
"latency",
17+
"restana"
18+
],
19+
"author": "Rolando Santamaria Maso <[email protected]>",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/BackendStack21/echo-api/issues"
23+
},
24+
"homepage": "https://github.com/BackendStack21/echo-api#readme",
25+
"dependencies": {
26+
"morgan": "^1.10.0",
27+
"restana": "^4.9.5"
28+
}
29+
}

0 commit comments

Comments
 (0)