Simple Node API to help with prototyping and scaffolding service layers as well as training.
569
complexapi)Simple Node API to help with prototyping and scaffolding service layers as well as training.
From time to time I need to carve out the infrastructure prior to beginning a project. This means setting up CICD pipelines, accounts within AWS, Azure, or GCP, and then creating the scaffolding for the service layer. This project acts as a placeholder for the various microservices within each zone. By deploying complexapi I can quickly create a "hello world" structure, to ensure the back end is in place, before starting work. As I develop each service, I can replace the complexapi placeholder with the actual service.
The default routes available are:
| Route | Details |
|---|---|
/ | Simple response with local parameters. |
/status | Expanded response including environment variables and a ping (/) of upstream URL(s). |
/test | Same as /status but invokes a recursive test upstream URL(s) on their /test route . |
NODE_BASE Is SetThe default routes available are:
| Route | Details |
|---|---|
/ | Simple response with local parameters. |
/%NODE_BASE% | Simple response with local parameters. |
/%NODE_BASE%/status | Expanded response including environment variables and a ping (/) of upstream URL(s). |
/%NODE_BASE%/test | Same as /status but invokes a recursive test upstream URL(s) on their /test route . |
You are able to add as many upstream URLs as you like by setting the UPSTREAM_* environment variables prefix. Some examples are:
| Variable | Value | Description |
|---|---|---|
UPSTREAM_A | localhost:3001 | Call to the default route. |
UPSTREAM_COOLROUTE | mycontainer:8080/public | Call to a container using a base route. |
The following environment variables are available:
| Variable | Default | Description |
|---|---|---|
NODE_ALIAS | Optional alias used for logging clarity. | |
NODE_BASE | / | Optional base route for the API. |
NODE_PORT | 3000 | Port the API listens to. |
The source code from Git contains three example scenarios.
examples/a-singleThe first is a very simple example that shows how to stand up a simple version of the service.
git clone https://github.com/FredLackey/complexapi.git
cd ./complexapi/examples/a-single
docker compose up
services:
SINGLE_SERVICE:
image: fredlackey/complexapi:0.0.3
container_name: complexapi-single
ports:
- "3000:3000"
networks:
- complexapi-network
networks:
complexapi-network:
drive
{
"name" : "complex-api-example",
"alias": "(not set)",
"base" : "(not set)",
"desc" : "Complex API Example",
"env" : "production",
"ver" : "0.0.3",
"date" : "2024-04-11T07:16:27.413Z",
"vars" : {
"HOME" : "/home/node",
"HOSTNAME" : "18acc4934cff",
"NODE_ENV" : "production",
"NODE_VERSION": "18.19.1",
"PATH" : "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"PWD" : "/home/node/app",
"YARN_VERSION": "1.22.19"
},
"tests": null
}
examples/b-parentchildThe second example combines two instances: one parent and one child.
git clone https://github.com/FredLackey/complexapi.git
cd ./complexapi/examples/b-parentchild
docker compose up
services:
COMPLEXAPI_PRIVATE:
image: fredlackey/complexapi:0.0.3
container_name: complexapi-private
environment:
- NODE_PORT=3000
- NODE_ALIAS=PRIVATE
networks:
- complexapi-network
COMPLEXAPI_PUBLIC:
image: fredlackey/complexapi:0.0.3
container_name: complexapi-public
environment:
- NODE_ALIAS=PUBLIC
- UPSTREAM_PRIVATE=complexapi-private:3000
networks:
- complexapi-network
ports:
- "3000:3000"
depends_on:
- COMPLEXAPI_PRIVATE
networks:
complexapi-network:
driver: bridge
Output from a GET call to http://localhost:3000/test. Note the calls to the the upstream service using its alias as the output payload:
{
"name" : "complex-api-example",
"alias": "PUBLIC",
"base" : "(not set)",
"desc" : "Complex API Example",
"env" : "production",
"ver" : "0.0.3",
"date" : "2024-04-11T07:20:02.629Z",
"vars" : {
"HOME" : "/home/node",
"HOSTNAME" : "d2525c513cbe",
"NODE_ALIAS" : "PUBLIC",
"NODE_ENV" : "production",
"NODE_VERSION" : "18.19.1",
"PATH" : "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"PWD" : "/home/node/app",
"UPSTREAM_PRIVATE": "complexapi-private:3000",
"YARN_VERSION" : "1.22.19"
},
"tests": {
"PRIVATE": {
"name" : "complex-api-example",
"alias": "PRIVATE",
"base" : "(not set)",
"desc" : "Complex API Example",
"env" : "production",
"ver" : "0.0.3",
"date" : "2024-04-11T07:20:02.670Z"
}
}
}
Other samples exist within the examples directory. Please feel free to explore them. They are too numerous to list here.
Please feel free to reach out if I can help in any way.
Fred Lackey
[email protected]
https://fredlackey.com
Content type
Image
Digest
sha256:b718bd4f9…
Size
85.2 MB
Last updated
over 2 years ago
docker pull fredlackey/complexapi