Skip to content

Commit 5399f83

Browse files
committed
Update Readme
1 parent 479d8c1 commit 5399f83

File tree

1 file changed

+22
-53
lines changed

1 file changed

+22
-53
lines changed

README.md

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

75
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.
8-
96
<!--- ENDEXCLUDE --->
107

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

13-
## Objectives
1411

12+
## Objectives
1513
- How to use the DataStax Cassandra Driver with Google Cloud Functions
1614
- How to use the Serverless Framework to set up Google Cloud Functions HTTP Endpoints
17-
15+
1816
## How it works
19-
2017
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.
2118

2219
## Get Started
23-
2420
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)
2521

2622
<!--- STARTEXCLUDE --->
27-
2823
## Prerequisites
29-
3024
Let's do some initial setup by creating a serverless(!) database.
3125

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

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

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

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

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)
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)
5042

5143
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.
52-
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-settings.png)
44+
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-settings.png)
5345

5446
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.
55-
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-settings-token.png)
47+
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-settings-token.png)
5648

5749
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.
58-
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-connect-bundle.png)
50+
![image](https://raw.githubusercontent.com/DataStax-Examples/sample-app-template/master/screenshots/astra-db-connect-bundle.png)
5951

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

6355
### Github
6456

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

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

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

7466
## 🚀 Getting Started Paths:
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)
67+
*Make sure you've completed the [prerequisites](#prerequisites) before starting this step*
68+
- [Running on your local machine](#running-on-your-local-machine)
7969

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

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

9078
1. Install the DataStax Cassandra Driver
91-
9279
```sh
9380
npm install cassandra-driver
9481
```
95-
9682
4. Install serverless-google-cloudfunctions plugin
97-
9883
```sh
9984
npm install serverless-google-cloudfunctions
10085
```
101-
10286
5. Configure `serverless.yml` with your project-id, credentials file, Contact Points ( public IP of GCP instance ), and Local Data Center ( likely `datacenter1` )
10387

10488
From the project directory, deploy your function. This should output the endpoints that you can use to access the database.
105-
10689
```sh
10790
sls deploy
10891
```
109-
110-
- When you are done, don't forget to clean things up with
111-
92+
* When you are done, don't forget to clean things up with
11293
```
11394
sls remove
11495
```
11596

11697
#### createCatalog
117-
11898
```sh
11999
curl -X POST https://us-central1-<project-id>.cloudfunctions.net/createCatalog
120-
```
121-
100+
````
122101
expected output:
123-
124102
```sh
125103
"Successfully created shopping.catalog schema"
126104
```
127-
128105
#### addItem
129-
130106
Note the `-H "Content-Type:application/json"` is required here.
131-
132107
```sh
133108
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
134109
```
135-
136110
expected output:
137-
138111
```sh
139112
{"query":"INSERT INTO shopping.catalog (item_id, name, description, price) VALUES (?, ?, ?, ?)","item_id":0,"name":"name_0","description":"desc_0","price":10.1}
140113
```
141-
142114
#### getItem
143-
144115
```sh
145116
curl -X GET https://us-central1-<project-id>.cloudfunctions.net/getItem/0
146117
```
147-
148118
expected output:
149-
150119
```sh
151120
{"query":"SELECT name, description, price FROM shopping.catalog WHERE item_id = ?","item_id":["0"],"name":"name_0","description":"desc_0","price":"10.1"}
152121
```

0 commit comments

Comments
 (0)