A dynamic microservices framework for building, connecting, and deploying cloud-native applications.
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
It is extremely common to run a REST API with a backend database as a standalone service so that it can be consumed by multiple, disparate applications.
In this example, you'll learn how to capture an API written in Node.js with a Postgres database backend in an Architect Component to enable automated deployments, networking and network security for your application - wherever it gets deployed.
In the architect.yml
file for this project, we describe this API as two deployable services. However, we also
leverage Architect's service discovery features to populate environment
secrets by reference. This not only allows us to automatically connect the services to each other, but it also allows
Architect to build strict network policies to whitelist the traffic between these services. Now we won't have any work ahead
of us to promote this stack from local dev all the way through to production!
Learn more about the architect.yml file
This API implements basic CRUD functionality for a simple Items
schema consisting of a name
and a rating
between 1 and 5.
You could use it to gather data about anything you want to rate, from your favorite restaurants, movies, and more!
{
"name": "string",
"rating": "integer"
}
The GET request returns the Items records in the following JSON payload:
[
{
"name": "string",
"rating": "integer",
"created_at": "string",
"updated_at": "string"
}
]
The architect.yml
file is declarative, which allows the Architect Component it describes to be run in any environment,
from local development all the way to production. Follow these steps to clone this repository and run the application
locally.
Once the deployment has completed, you can reach your new service by going to http://api.arc.localhost.
# Clone the repository and navigate to this directory
$ git clone git@github.com:architect-templates/node-rest-api.git
$ cd ./node-rest-api
# Deploy locally using the dev command
$ architect dev .
Want to try deploying this to a cloud environment? Architect's got you covered there, too! It only takes a minute to sign up for a free account.
You can then register the component
to your free environment and deploy the component
using the commands below from the node-rest-api
directory.
The <account-name>
is the name you used when you created your account in Architect Cloud. Use "example-environment" for
the <environment-name>
to deploy to the free environment that is created when you register with Architect.
# Register and tag the component with Architect Cloud's component registry
$ architect register . --tag latest --account <account-name>
# Deploy to Architect Cloud
$ architect deploy node-rest-api -a <account-name> -e <environment-name>