You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-17Lines changed: 18 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
-
t# Quickstart in Couchbase with Spring Boot and Java
1
+
# Quickstart in Couchbase with Spring Boot and Java
2
2
3
3
#### REST API using Couchbase Capella in Java using Spring Boot
4
4
5
-
Often, the first step developers take after creating their database is to create a REST API that can perform Create, Read, Update, and Delete (CRUD) operations for that database. This repo is designed to teach you and give you a starter project (in Java using Spring Boot) to generate such a REST API. After you have installed the travel-sample bucket in your database, you can run this application which is a REST API with Swagger documentation so that you can learn:
5
+
Often, the first step developers take after creating their database is to create a REST API that can perform Create, Read, Update, and Delete (CRUD) operations for that database. This repo is designed to teach you and give you a starter project (in Java using Spring Boot) to generate such a REST API. After you have loaded the travel-sample bucket in your database, you can run this application which is a REST API with Swagger documentation so that you can learn:
6
6
7
-
1. How to create, read, update, and delete documents using Key-Value[ operations](https://docs.couchbase.com/java-sdk/current/howtos/kv-operations.html) (KV operations). KV operations are unique to Couchbase and provide super fast (think microseconds) queries.
7
+
1. How to create, read, update, and delete documents using Key-Value[ operations](https://docs.couchbase.com/java-sdk/current/howtos/kv-operations.html) (KV operations). KV operations are unique to Couchbase and provide super fast (under millisecond) operations.
8
8
2. How to write simple parametrized [N1QL queries](https://docs.couchbase.com/java-sdk/current/howtos/n1ql-queries-with-sdk.html) using the built-in travel-sample bucket.
9
9
10
10
Full documentation for the tutorial can be found on the [Couchbase Developer Portal](https://developer.couchbase.com/tutorial-quickstart-java-springboot/).
@@ -15,13 +15,11 @@ To run this prebuilt project, you will need:
15
15
16
16
-[Couchbase Capella](https://www.couchbase.com/products/capella/) cluster with [travel-sample](https://docs.couchbase.com/java-sdk/current/ref/travel-app-data-model.html) bucket loaded.
17
17
- To run this tutorial using a self-managed Couchbase cluster, please refer to the [appendix](#running-self-managed-couchbase-cluster).
- Ensure that the Java version is compatible with the Couchbase SDK. [Please check the link for compatibility](https://docs.couchbase.com/java-sdk/current/project-docs/compatibility.html#jdk-compat)
20
+
- Loading Travel Sample Bucket:
21
+
- If `travel-sample` is not loaded in your Capella cluster, you can load it by following the instructions for your Capella Cluster. [Load travel-sample bucket in Couchbase Capella](https://docs.couchbase.com/cloud/clusters/data-service/import-data-documents.html#import-sample-data)
The dependencies for the application are specified in the `pom.xml` file in the source folder. Dependencies can be installed through `mvn` the default package manager for Java.
36
+
The dependencies for the application are specified in the `pom.xml` file in the root folder. Dependencies can be installed through `mvn` the default package manager for Java.
39
37
40
38
```
41
39
mvn clean install -DskipTests=true
@@ -56,8 +54,6 @@ Specifically, you need to do the following:
56
54
57
55
All configuration for communication with the database is read from the application properties. We have provided a convenience feature in this quickstart to read the properties from a local file, `application.properties` in the `src/main/resources` folder.
58
56
59
-
You can also use your system environment variables to set the properties. The properties are read from the environment variables if they are set. The properties are read from the `application.properties` file if the environment variables are not set.
@@ -70,8 +66,12 @@ Instead of the DB_CONN_STR, DB_USERNAME and DB_PASSWORD, you need to add the val
70
66
71
67
> Note: The connection string expects the `couchbases://` or `couchbase://` part.
72
68
69
+
You can also use your system environment variables to set the properties. The properties are read from the environment variables if they are set. The properties are read from the `application.properties` file if the environment variables are not set.
70
+
73
71
## Running The Application
74
72
73
+
You can add environment variables DB_CONN_STR, DB_USERNAME and DB_PASSWORD to your system environment variables or you can update the `application.properties` file in the `src/main/resources` folder.
74
+
75
75
### Directly on Machine
76
76
77
77
At this point, we have installed the dependencies, loaded the travel-sample data and configured the application with the credentials. The application is now ready and you can run it.
@@ -106,6 +106,7 @@ Once the application starts, you can see the details of the application on the l
106
106
The application will run on port 8080 of your local machine (http://localhost:8080). You will find the interactive Swagger documentation of the API if you go to the URL in your browser. Swagger documentation is used in this demo to showcase the different API endpoints and how they can be invoked. More details on the Swagger documentation can be found in the [appendix](#swagger-documentation).
To test your application, you can use Maven (mvn) to run the test suite. Here are the steps to run the tests:
@@ -146,16 +147,16 @@ mvn test -Dtest=org.couchbase.quickstart.springboot.controllers.RouteIntegration
146
147
147
148
For this quickstart, we use three collections, `airport`, `airline` and `routes` that contain sample airports, airlines and airline routes respectively. The routes collection connects the airports and airlines as seen in the figure below. We use these connections in the quickstart to generate airports that are directly connected and airlines connecting to a destination airport. Note that these are just examples to highlight how you can use SQL++ queries to join the collections.
148
149
149
-

150
+

150
151
151
152
### Extending API by Adding New Entity
152
153
153
154
If you would like to add another entity to the APIs, these are the steps to follow:
154
155
155
-
- Create the new entity (collection) in the Couchbase scope. You can create the collection using the [SDK](https://docs.couchbase.com/java-sdk/current/howtos/provisioning-cluster-resources.html#collection-management) or via the [Couchbase Server interface](https://docs.couchbase.com/cloud/n1ql/n1ql-language-reference/createcollection.html).
156
+
- Create a new collection in the Couchbase scope. You can create new collections using the [SDK](https://docs.couchbase.com/java-sdk/current/howtos/provisioning-cluster-resources.html#collection-management) or via the [Couchbase Server interface](https://docs.couchbase.com/cloud/n1ql/n1ql-language-reference/createcollection.html).
156
157
- Define the routes in a new class in the `controllers` package similar to the existing routes like `AirportController.java`.
157
-
- Define the service in a new class in the `services` package similar to the existing services like `AirportService.java`. You'll have to implement the service interface `AirportServiceImpl.java`.
158
-
- Define the repository in a new class in the `repositories` package similar to the existing repositories like `AirportRepository.java`. You'll have to implement the repository interface `AirportRepositoryImpl.java`.
158
+
- Define the service in a new class in the `services` package similar to the existing services like `AirportService.java`.
159
+
- Define the repository in a new class in the `repositories` package similar to the existing repositories like `AirportRepository.java`.
0 commit comments