Skip to content

Open Liberty sample application for accessing Cloudant

Notifications You must be signed in to change notification settings

OpenLiberty/sample-cloudant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloudant Sample

This sample shows how to store data with Cloudant using CDI and MicroProfile Config, as well as data validation with Jakarta Bean Validation.

Environment Set Up

To run this sample, first download or clone this repo - to clone:

git clone [email protected]:OpenLiberty/sample-cloudant.git

Setup Cloudant / CouchDb

Running the Sample

From inside the sample-cloudant directory, build and start the application in Open Liberty with the following command:

./mvnw liberty:dev

Once the server has started, the application is available at http://localhost:9080

Try it out

Give the sample a try by registering a crew member. Enter a name (a String), an ID Number (an Integer), and select a Rank from the menu, then click 'Register Crew Member'.

Two more boxes will appear, one with your crew members (which you can click to remove) and one showing how your data looks in Cloudant.

Stop Cloudant / CouchDb

How it works

Calling POST /{id} on the endpoint uses Jakarta Validation to validate the data we receive from the front end. CrewMember.java shows the constraints as well as the messages we return to the user if those constraints aren't met.

@NotEmpty(message = "All crew members must have a name!")
private String name;

@Pattern(regexp = "(Captain|Officer|Engineer)",  message = "Crew member must be one of the listed ranks!")
private String rank;

@Pattern(regexp = "^\\d+$", message = "ID Number must be a non-negative integer!")
private String crewID; 

About

Open Liberty sample application for accessing Cloudant

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published