GithubHelp home page GithubHelp logo

melienherrera / getting-started-with-astra-java Goto Github PK

View Code? Open in Web Editor NEW

This project forked from datastax-examples/getting-started-with-astra-java

0.0 0.0 0.0 136 KB

Example REST API in Java showing how to connect to and query DataStax Astra databases

Home Page: https://astra.datastax.com/register

License: Apache License 2.0

Dockerfile 0.44% Java 99.56%

getting-started-with-astra-java's Introduction

Getting Started with Apache Cassandra™ and Java using DataStax Astra DB

50 minutes, Intermediate, Start Building

This provides an example REST backend built in Java using Spring Boot for use with the Getting Started with Astra UI.

image

Objectives

  • How to connect to Astra DB via the Secure Connect Bundle
  • How to manage a Cassandra Session within a JAVA web application

How this Works

This is an example of a Spring Boot Microservice for use with the Astra Getting Started UI which is found here.

Get Started

To build and play with this app, follow the build instructions that are located here: https://github.com/DataStax-Examples/getting-started-with-astra-java

Prerequisites

Let's do some initial setup by creating a serverless(!) database.

DataStax Astra

  1. Create a DataStax Astra account if you don't already have one: image

  2. On the home page. Locate the button Create Database image

  3. Locate the Get Started button to continue image

  4. Define a database name, keyspace name and select a database region, then click create database. image

  5. Your Astra DB will be ready when the status will change from Pending to Active 💥💥💥 image

  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. image

  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. image

  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. image

  9. Make note of where to use the Client Id and Client Secret that is part of the Application Token that we generated earlier. image

Github

  1. Click Use this template at the top of the GitHub Repository: image

  2. Enter a repository name and click 'Create repository from template': image

  3. Clone the repository: image

🚀 Getting Started Paths:

Make sure you've completed the prerequisites before starting this step

Running on your local machine

Make sure that you have:

  • Java 11+
  • An Astra DB compatible Java driver, instructions may be found here to install this locally.
  • An Astra database with the CQL schema located in schema.cql already added.
  • The username, password, keyspace name, and secure connect bundle downloaded from your Astra DB. For information on how to obtain these credentials please read the documentation found here.

This application is a Spring Boot web application. This sample can be run from the root directory using:

cd getting-started-with-astra-java

mvn spring-boot:run

This will startup the application running on http://localhost:8080

You will know that you are up and working when you get the following in your terminal window:

16:23:01.569 INFO  com.datastax.astra.GettingStartedWithAstra  : Started GettingStartedWithAstra in 1.851 seconds (JVM running for 2.39)

Access the API documentation from a browser

http://localhost:8080

Note: If you want to change the listening port of the application, locate the file src/main/resources/application.yml and change key server.port

Setup the user interface to use this backend

To setup the UI to connect to Java backend define a .env file in the getting-started-with-astra-ui project main directory. Inside the file it should have one entry pointing to this project's API endpoint:

BASE_ADDRESS=http://localhost:8080/api

Once you start that project with a npm run build it will point the UI to the backend API which will then be using Astra DB as a database. When you first connect to the UI, a dialog box will open asking for Astra DB connection information.

getting-started-with-astra-java's People

Contributors

kidrecursive avatar clun avatar msmygit avatar beccam avatar meerabhandare-datastax avatar pmcfadin avatar bechbd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.