Skip to content
63 changes: 52 additions & 11 deletions bindings/javascript/http/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
# Dapr Bindings (HTTP)

In this quickstart, you'll create a microservice to demonstrate Dapr's bindings API to work with external systems as inputs and outputs. The service listens to input binding events from a system CRON and then outputs the contents of local data to a PostreSql output binding.
In this quickstart, you'll create a microservice to demonstrate Dapr's bindings API to work with external systems as inputs and outputs. The service listens to input binding events from a system CRON and then outputs the contents of local data to a PostgreSQL output binding.

Visit [this](https://docs.dapr.io/developing-applications/building-blocks/bindings/) link for more information about Dapr and Bindings.

> **Note:** This example leverages only HTTP REST. If you are looking for the example using the Dapr SDK [click here](../sdk).
> **Note:** This example leverages only HTTP REST. If you are looking for the example using the Dapr SDK [click here](../sdk).

This quickstart includes one service:

- Javascript/Node.js service `bindings`

### Run and initialize PostgreSQL container
* Javascript/Node.js service `bindings`

1. Open a new terminal, change directories to `../../db`, and run the container with [Docker Compose](https://docs.docker.com/compose/):
---

## Prerequisites

* [Docker](https://docs.docker.com/get-docker/)
* [Dapr CLI](https://docs.dapr.io/getting-started/install-dapr-cli/)
* Node.js 14+
* npm
* Initialize Dapr: `dapr init`

---

## Run and initialize PostgreSQL container

1. Open a new terminal, change directories to `../../db`, and run the container with Docker Compose:

<!-- STEP
name: Run and initialize PostgreSQL container
Expand All @@ -28,9 +40,11 @@ docker compose up -d

<!-- END_STEP -->

### Run Javascript service with Dapr
---

## Run Javascript service with Dapr

2. Open a new terminal window, change directories to `./batch` in the quickstart directory and run:
2. Open a new terminal window, change directories to `./batch` in the quickstart directory and install dependencies:

<!-- STEP
name: Install Javascript dependencies
Expand All @@ -44,14 +58,16 @@ cd ..

<!-- END_STEP -->

---

3. Run the Javascript service app with Dapr:

<!-- STEP
name: Run batch-http service
expected_stdout_lines:
- 'insert into orders (orderid, customer, price) values (1, ''John Smith'', 100.32)'
- 'insert into orders (orderid, customer, price) values (2, ''Jane Bond'', 15.4)'
- 'insert into orders (orderid, customer, price) values (3, ''Tony James'', 35.56)'
- 'insert into orders (orderid, customer, price) values (1, ''John Smith'', 100.32);'
- 'insert into orders (orderid, customer, price) values (2, ''Jane Bond'', 15.4);'
- 'insert into orders (orderid, customer, price) values (3, ''Tony James'', 35.56);'
- 'Finished processing batch'
expected_stderr_lines:
output_match_mode: substring
Expand All @@ -64,3 +80,28 @@ dapr run -f .
```

<!-- END_STEP -->

The `-f` flag runs the application using the **Multi-App Run configuration** defined in `dapr.yaml`, automatically starting both the application and its Dapr sidecar.

The cron input binding triggers the service every 10 seconds, and the service writes records to PostgreSQL using the output binding.

---

## Verify Data Persistence

4. Open a new terminal window and run the following command to check the rows in the database:

<!-- STEP
name: Verify Data Persistence
expected_stdout_lines:
- 'orderid | customer | price'
- '---------+------------+--------'
expected_stderr_lines:
output_match_mode: substring
-->

```bash
docker exec postgres psql -U postgres -d orders -c "SELECT * FROM orders;"
```

<!-- END_STEP -->