Skip to content

DevMandy/node-rest-api-demo

Repository files navigation

Architect Logo

A dynamic microservices framework for building, connecting, and deploying cloud-native applications.


Node.js Logo

Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.


Node.js Starter Project

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

Using the API

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!

The Items Schema:

  {
    "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"
  }
 ] 

Running Locally

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 .

Deploying to the Cloud

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>

About

Node REST API for CI/CD demo.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •