{"id":45157458,"url":"https://github.com/couchbase-examples/kotlin-quickstart","last_synced_at":"2026-02-20T05:02:54.766Z","repository":{"id":37811557,"uuid":"503759304","full_name":"couchbase-examples/kotlin-quickstart","owner":"couchbase-examples","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-15T09:01:49.000Z","size":995,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-15T10:46:19.342Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/couchbase-examples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-06-15T12:38:34.000Z","updated_at":"2025-01-15T09:01:47.000Z","dependencies_parsed_at":"2024-04-18T18:35:50.053Z","dependency_job_id":"6d081364-7281-40c5-a97b-3ed7d5276056","html_url":"https://github.com/couchbase-examples/kotlin-quickstart","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/couchbase-examples/kotlin-quickstart","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase-examples%2Fkotlin-quickstart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase-examples%2Fkotlin-quickstart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase-examples%2Fkotlin-quickstart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase-examples%2Fkotlin-quickstart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/couchbase-examples","download_url":"https://codeload.github.com/couchbase-examples/kotlin-quickstart/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase-examples%2Fkotlin-quickstart/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29641929,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-20T03:21:14.183Z","status":"ssl_error","status_checked_at":"2026-02-20T03:18:24.455Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-02-20T05:02:43.916Z","updated_at":"2026-02-20T05:02:54.761Z","avatar_url":"https://github.com/couchbase-examples.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Quickstart in Couchbase with Kotlin and Ktor\n\n#### REST API using Couchbase Capella in Kotlin and Ktor\n\nOften, the first step developers do 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 Kotlin using Ktor) to generate such a REST API. After you have installed travel-sample bucket in your database, you can run this application which is a REST API with Swagger documentation so that you can learn:\n\n1. How to create, read, update, and delete documents using [Key Value operations](https://docs.couchbase.com/kotlin-sdk/current/howtos/kv-operations.html) (KV operations). KV operations are unique to couchbase and provide super fast (think microseconds) queries.\n2. How to write simple parametrized [SQL++ queries](https://docs.couchbase.com/kotlin-sdk/current/howtos/n1ql-queries.html) using the built-in travel-sample bucket.\n\nFull documentation can be found on the [Couchbase Developer Portal](https://developer.couchbase.com/tutorial-quickstart-kotlin-ktor).\n\n## Prerequisites\nTo run this prebuilt project, you will need:\n\n- [Couchbase Capella](https://www.couchbase.com/products/capella/) cluster with [travel-sample](https://docs.couchbase.com/kotlin-sdk/current/ref/travel-app-data-model.html) bucket loaded.\n    - To run this tutorial using a self managed Couchbase cluster, please refer to the [appendix](#running-self-managed-couchbase-cluster).\n- [Java JDK](https://docs.couchbase.com/kotlin-sdk/current/project-docs/compatibility.html#jdk-compat) installed.\n    - Ensure that the Java version is [compatible](https://docs.couchbase.com/kotlin-sdk/current/project-docs/compatibility.html#jdk-compat) with the Couchbase SDK.\n- Code Editor installed (Vim, IntelliJ IDEA, Eclipse, or Visual Studio Code)\n- Loading Travel Sample Bucket\n    - If travel-sample is not loaded in your Capella cluster, you can load it by following the instructions for your Capella Cluster:\n        - [Load travel-sample bucket in Couchbase Capella](https://docs.couchbase.com/cloud/clusters/data-service/import-data-documents.html#import-sample-data)\n\n## App Setup\n\nWe will walk through the different steps required to get the application running.\n\n### Cloning Repo\n\n```shell\ngit clone https://github.com/couchbase-examples/kotlin-quickstart.git\n```\n\n### Install Dependencies\n\n```shell\n./gradlew build -x test\n```\n### Dependency Injection via Couchbase Koin module\n\nThe quickstart code provides a Koin module that exports configuration, cluster, bucket and scope beans to the application.\n```\n// Creates a cluster bean\nfun createCluster(configuration: CouchbaseConfiguration): Cluster {\n  return Cluster.connect(\n    connectionString = configuration.connectionString,\n    username = configuration.username,\n    password = configuration.password,\n  )\n}\n\n\n// Creates a bucket bean\n@ExperimentalTime\nfun createBucket(cluster: Cluster, configuration: CouchbaseConfiguration): Bucket {\n  val result : Bucket?\n  runBlocking {\n    result = cluster.bucket(configuration.bucket).waitUntilReady(10.seconds)\n  }\n  return result\n}\n\n// Creates a bucket scope bean\nfun createScope(bucket: Bucket, configuration: CouchbaseConfiguration): Scope {\n  return bucket.scope(configuration.scope)\n}\n```\n\u003e _from [`src/main/kotlin/com/couchbase/kotlin/quickstart/CouchbaseConfiguration.kt`](https://github.com/couchbase-examples/kotlin-quickstart/blob/main/src/main/kotlin/com/couchbase/kotlin/quickstart/CouchbaseConfiguration.kt)_\n\nConfigured database objects like the bucket and scope must exist on the cluster prior to starting the application.\n\n### Setup Database Configuration\n\nTo know more about connecting to your Capella cluster, please follow the [instructions](https://docs.couchbase.com/cloud/get-started/connect.html).\n\nSpecifically, you need to do the following:\n\n- Create the [database credentials](https://docs.couchbase.com/cloud/clusters/manage-database-users.html) to access the travel-sample bucket (Read and Write) used in the application.\n- [Allow access](https://docs.couchbase.com/cloud/clusters/allow-ip-address.html) to the Cluster from the IP on which the application is running.\n\nAll configuration for communication with the database is stored in the `src/main/resources/application.conf` file under the `couchbase` section:\n\n```\ncouchbase {\n    connectionString = \"couchbases://yourassignedhostname.cloud.couchbase.com\"\n    username = \"Administrator\"\n    password = \"password\"\n    bucket = \"travel-sample\"\n    scope = \"inventory\"\n}\n```\n\u003e _from [`src/main/resources/application.conf`](https://github.com/couchbase-examples/kotlin-quickstart/blob/main/src/main/resources/application.conf)_\n\n\u003e Note: The connection string expects the `couchbases://` or `couchbase://` part.\n\n\nThis includes the connection string, username, password, bucket and scope names. The default username is assumed to be `Administrator` and the default password is assumed to be `password`.\nIf these are different in your environment you will need to change them before running the application.\n\n## Running The Application\n\n### Directly on Machine\n\nAt 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.\n\n```shell\n./gradlew run\n```\n\n### Using Docker\n\n- Build the Docker image\n\n```shell \ndocker build -t couchbase-koltin-quickstart .\n```\n\n- Run the docker image\n\n```shell \ndocker run -e DB_CONN_STR=\u003cconnection_string\u003e -e DB_USERNAME=\u003cuser_with_read_write_permission_to_travel-sample_bucket\u003e -e DB_PASSWORD=\u003cpassword_for_user\u003e -p 8080:8080 couchbase-koltin-quickstart\n```\n\nYou can access the Application on http://0.0.0.0:8080\n\n### Verifying the Application\n\nOnce the application starts, you can see the details of the application on the logs.\n\n![Application Startup](app_startup.png)\n\nThe application will run on port 8080 of your local machine (http://0.0.0.0:8080). You will find the Swagger documentation of the API if you go to the URL in your browser.\nSwagger documentation is used in this demo to showcase the different API end points and how they can be invoked. More details on the Swagger documentation can be found in the [appendix](#swagger-documentation).\n\n![Swagger Documentation](swagger_documentation.png)\n\n## Running Tests\n\nTo run the standard integration tests, use the following command:\n\n```sh\n./gradlew test\n```\n\n## Appendix\n\n### Data Model\n\nFor 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.\n\n![travel sample data model](travel_sample_data_model.png)\n\n### Extending API by Adding New Entity\n\nIf you would like to add another entity to the APIs, these are the steps to follow:\n\n- Create the new entity (collection) in the Couchbase bucket. You can create the collection using the [SDK](https://docs.couchbase.com/sdk-api/couchbase-kotlin-client-1.1.8/kotlin-client/com.couchbase.client.kotlin.manager.collection/-collection-manager/index.html#2117033537%2FFunctions%2F1565675143) or via the [Couchbase Server interface](https://docs.couchbase.com/cloud/n1ql/n1ql-language-reference/createcollection.html).\n- Define the routes in a file inside the `src/main/kotlin/com/couchbase/kotlin/quickstart/routes` folder similar to the existing routes.\n- Define the services in a new file inside the `src/main/kotlin/com/couchbase/kotlin/quickstart/services` folder similar to the existing services.\n- Define the repository for this collection inside a new file inside the `src/main/kotlin/com/couchbase/kotlin/quickstart/repositories` folder similar to the existing repositories.\n- Add the tests for the new routes in a new file in the `src/test/kotlin/com/couchbase/kotlin/quickstart` folder similar to the existing ones.\n\n### Running Self Managed Couchbase Cluster\n\nIf you are running this quickstart with a self managed Couchbase cluster, you need to [load](https://docs.couchbase.com/server/current/manage/manage-settings/install-sample-buckets.html) the travel-sample data bucket in your cluster and generate the credentials for the bucket.\n\nYou need to update the connection string and the credentials in the [`src/main/resources/application.conf`](https://github.com/couchbase-examples/kotlin-quickstart/blob/main/src/main/resources/application.conf) file in the source folder.\n\n\u003e **NOTE:** Couchbase must be installed and running prior to running the the ASP.NET app.\n\n### Swagger Documentation\n\nSwagger documentation provides a clear view of the API including endpoints, HTTP methods, request parameters, and response objects.\n\nClick on an individual endpoint to expand it and see detailed information. This includes the endpoint's description, possible response status codes, and the request parameters it accepts.\n\n#### Trying Out the API\n\nYou can try out an API by clicking on the \"Try it out\" button next to the endpoints.\n\n- Parameters: If an endpoint requires parameters, Swagger UI provides input boxes for you to fill in. This could include path parameters, query strings, headers, or the body of a POST/PUT request.\n\n- Execution: Once you've inputted all the necessary parameters, you can click the \"Execute\" button to make a live API call. Swagger UI will send the request to the API and display the response directly in the documentation. This includes the response code, response headers, and response body.\n\n#### Models\n\nSwagger documents the structure of request and response bodies using models. These models define the expected data structure using JSON schema and are extremely helpful in understanding what data to send and expect.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcouchbase-examples%2Fkotlin-quickstart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcouchbase-examples%2Fkotlin-quickstart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcouchbase-examples%2Fkotlin-quickstart/lists"}