Skip to content

Commit 4c01bcc

Browse files
committed
Update Readme
1 parent 0eb3e44 commit 4c01bcc

File tree

1 file changed

+53
-22
lines changed

1 file changed

+53
-22
lines changed

README.md

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,152 @@
11
<!--- STARTEXCLUDE --->
2+
23
# Astra DB REST API with Google Cloud Functions in Node.js
3-
*30 minutes, Intermediate, [Start Building](https://github.com/DataStax-Examples/google-cloud-functions-nodejs#prerequisites)*
4+
5+
_30 minutes, Intermediate, [Start Building](https://github.com/DataStax-Examples/google-cloud-functions-nodejs#prerequisites)_
46

57
This example shows how to use [Google Cloud Functions](https://cloud.google.com/functions/) with the [Node.js DataStax Cassandra Driver](https://docs.datastax.com/en/developer/nodejs-driver/latest) to set up a basic REST API for a Cassandra database via HTTP Endpoints. The [Serverless Framework](https://serverless.com/) is used to facilitate the setup and deployment of the functions.
6-
<!--- ENDEXCLUDE --->
78

9+
<!--- ENDEXCLUDE --->
810

911
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-sample-app-default.png)
1012

11-
1213
## Objectives
14+
1315
- How to use the DataStax Cassandra Driver with Google Cloud Functions
1416
- How to use the Serverless Framework to set up Google Cloud Functions HTTP Endpoints
15-
17+
1618
## How it works
19+
1720
The Serverless Framework handles the packaging and deployment of the functions to the Google Cloud resources. Once the functions are deployed, the DataStax Cassandra Driver establishes the connection to the database and returns the results via the Google Cloud HTTP Endpoints which can be accessed to interact with the database.
1821

1922
## Get Started
23+
2024
To build and play with this app, follow the build instructions that are located here: [https://github.com/DataStax-Examples/google-cloud-functions-nodejs](https://github.com/DataStax-Examples/google-cloud-functions-nodejs#prerequisites)
2125

2226
<!--- STARTEXCLUDE --->
27+
2328
## Prerequisites
29+
2430
Let's do some initial setup by creating a serverless(!) database.
2531

2632
### DataStax Astra
33+
2734
<!--- enter a unique UTM_CODE for your sample app below --->
35+
2836
1. Create a [DataStax Astra account](https://dtsx.io/3jENJkP) if you don't already have one:
29-
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-register-basic-auth.png)
37+
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-register-basic-auth.png)
3038

3139
2. On the home page. Locate the button **`Create Database`**
32-
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-dashboard.png)
40+
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-dashboard.png)
3341

3442
3. Locate the **`Get Started`** button to continue
35-
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-select-plan.png)
43+
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-select-plan.png)
3644

3745
4. Define a **database name**, **keyspace name** and select a database **region**, then click **create database**.
38-
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-create-db.png)
46+
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-create-db.png)
3947

40-
5. Your Astra DB will be ready when the status will change from *`Pending`* to **`Active`** 💥💥💥
41-
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-active.png)
48+
5. Your Astra DB will be ready when the status will change from _`Pending`_ to **`Active`** 💥💥💥
49+
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-active.png)
4250

4351
6. After your database is provisioned, we need to generate an Application Token for our App. Go to the `Settings` tab in the database home screen.
44-
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-settings.png)
52+
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-settings.png)
4553

4654
7. Select `Admin User` for the role for this Sample App and then generate the token. Download the CSV so that we can use the credentials we need later.
47-
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-settings-token.png)
55+
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-settings-token.png)
4856

4957
8. After you have your Application Token, head to the database connect screen and select the driver connection that we need. Go ahead and download the `Secure Bundle` for the driver.
50-
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-connect-bundle.png)
58+
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-connect-bundle.png)
5159

5260
9. Make note of where to use the `Client Id` and `Client Secret` that is part of the Application Token that we generated earlier.
53-
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-connect-bundle-driver.png)
61+
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-connect-bundle-driver.png)
5462

5563
### Github
5664

5765
1. Click `Use this template` at the top of the [GitHub Repository](https://github.com/DataStax-Examples/google-cloud-functions-nodejs):
58-
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/github-use-template.png)
66+
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/github-use-template.png)
5967

6068
2. Enter a repository name and click 'Create repository from template':
61-
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/github-create-repository.png)
69+
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/github-create-repository.png)
6270

6371
3. Clone the repository:
64-
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/github-clone.png)
72+
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/github-clone.png)
6573

6674
## 🚀 Getting Started Paths:
67-
*Make sure you've completed the [prerequisites](#prerequisites) before starting this step*
68-
- [Running on your local machine](#running-on-your-local-machine)
75+
76+
_Make sure you've completed the [prerequisites](#prerequisites) before starting this step_
77+
78+
- [Running on your local machine](#running-on-your-local-machine)
6979

7080
### Running on your local machine
71-
Before running with this example, head over to the [SETUP-README](SETUP-README.md) for instructions on how to
81+
82+
Before running with this example, head over to the [SETUP-README](https://raw.githubusercontent.com/DataStax-Examples/google-cloud-functions-nodejs/blob/master/SETUP-README.md) for instructions on how to
83+
7284
1. launch an instance in Google Cloud
7385
2. install and start a Cassandra database
7486
3. setup your local development environment for Node.js and [serverless](https://serverless.com)
7587

7688
Once the above is completed, you will have all of the needed pieces in place to run this example.
7789

7890
1. Install the DataStax Cassandra Driver
91+
7992
```sh
8093
npm install cassandra-driver
8194
```
95+
8296
4. Install serverless-google-cloudfunctions plugin
97+
8398
```sh
8499
npm install serverless-google-cloudfunctions
85100
```
101+
86102
5. Configure `serverless.yml` with your project-id, credentials file, Contact Points ( public IP of GCP instance ), and Local Data Center ( likely `datacenter1` )
87103

88104
From the project directory, deploy your function. This should output the endpoints that you can use to access the database.
105+
89106
```sh
90107
sls deploy
91108
```
92-
* When you are done, don't forget to clean things up with
109+
110+
- When you are done, don't forget to clean things up with
111+
93112
```
94113
sls remove
95114
```
96115

97116
#### createCatalog
117+
98118
```sh
99119
curl -X POST https://us-central1-<project-id>.cloudfunctions.net/createCatalog
100-
````
120+
```
121+
101122
expected output:
123+
102124
```sh
103125
"Successfully created shopping.catalog schema"
104126
```
127+
105128
#### addItem
129+
106130
Note the `-H "Content-Type:application/json"` is required here.
131+
107132
```sh
108133
curl -X POST -H "Content-Type:application/json" -d '{"item_id": 0, "name": "name_0", "description": "desc_0", "price": 10.1}' https://us-central1-<project-id>.cloudfunctions.net/addItem
109134
```
135+
110136
expected output:
137+
111138
```sh
112139
{"query":"INSERT INTO shopping.catalog (item_id, name, description, price) VALUES (?, ?, ?, ?)","item_id":0,"name":"name_0","description":"desc_0","price":10.1}
113140
```
141+
114142
#### getItem
143+
115144
```sh
116145
curl -X GET https://us-central1-<project-id>.cloudfunctions.net/getItem/0
117146
```
147+
118148
expected output:
149+
119150
```sh
120151
{"query":"SELECT name, description, price FROM shopping.catalog WHERE item_id = ?","item_id":["0"],"name":"name_0","description":"desc_0","price":"10.1"}
121152
```

0 commit comments

Comments
 (0)