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
The application will run on the port specified by Rails on your local machine (eg: http://localhost:3000). 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.
For this quickstart, we use three collections, airport, airline and routes that contain sample airports, airlines and airline routes respectively. The route 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.
121
125
122
-

123
-
124
-
## Extending API by Adding New Entity
125
-
126
-
If you would like to add another entity to the APIs, these are the steps to follow:
127
-
128
-
1. Create a new model: Create a new model for the entity in the `app/models` folder. This model should contain the schema for the entity.
129
-
2. Create the new route: In Rails, you can create a new route by adding a new resource in the `config/routes.rb` file. This file should contain the logic for the new entity's CRUD operations.
130
-
3. Create the new controller: Create a new controller for the entity in the `app/controllers` folder. This controller should contain the logic for the new entity's CRUD operations.
131
-
4. Add the integration tests: Add integration tests for the new entity in the `test/integration` folder. This ensures that the new entity's CRUD operations are tested. The test file should be named `<entity>_spec.rb`.
132
-
133
-
Following these steps ensures a systematic and organized approach to expanding the API functionality with a new entity.
- Open the `spec/requests/api/v1/customers_spec.rb` file.
156
+
- Define the Swagger documentation for the new entity's API endpoints using RSpec and the `rswag` gem.
157
+
- Specify the request and response parameters, headers, and schemas for each endpoint.
158
+
- Example:
159
+
```ruby
160
+
require 'swagger_helper'
161
+
162
+
describe 'Customers API', type: :request do
163
+
path '/api/v1/customers' do
164
+
get 'Retrieves all customers' do
165
+
tags 'Customers'
166
+
produces 'application/json'
167
+
168
+
response '200', 'customers retrieved' do
169
+
schema type: :array,
170
+
items: {
171
+
type: :object,
172
+
properties: {
173
+
id: { type: :integer },
174
+
name: { type: :string },
175
+
email: { type: :string }
176
+
},
177
+
required: ['id', 'name', 'email']
178
+
}
179
+
180
+
run_test!
181
+
end
182
+
end
183
+
end
184
+
end
185
+
```
186
+
187
+
5. Add integration tests:
188
+
- Create a new integration test file for the entity in the `test/integration` folder.
189
+
- Write integration tests to cover the CRUD operations of the new entity.
190
+
- Example: `test/integration/customers_spec.rb`
191
+
```ruby
192
+
require 'rails_helper'
193
+
194
+
RSpec.describe 'Customers API', type: :request do
195
+
describe 'GET /api/v1/customers' do
196
+
# Add tests for retrieving customers
197
+
end
198
+
199
+
describe 'POST /api/v1/customers' do
200
+
# Add tests for creating a customer
201
+
end
202
+
203
+
# Add more tests for other CRUD operations
204
+
end
205
+
```
206
+
207
+
6. Run tests and verify:
208
+
- Run the integration tests using the command `bundle exec rspec test/integration`.
209
+
- Ensure that all tests pass and the new entity's CRUD operations are working as expected.
210
+
211
+
By following these steps, you can systematically extend the API functionality with a new entity while maintaining a well-structured and tested codebase.
134
212
135
213
## Running Self-Managed Couchbase Cluster
136
214
137
215
If you are running this quickstart with a self-managed Couchbase cluster, you need to load the travel-sample data bucket in your cluster and generate the credentials for the bucket by creating a user.
138
216
139
-
You need to update the connection string and the credentials in the `dev.env` file in the root folder.
217
+
You need to update the connection string and the credentials in the `couchbase.yml` file in the `config` folder.
140
218
141
-
Note: Couchbase Server must be installed and running prior to running this app.
219
+
Note: Couchbase Server must be installed and running before running this app.
0 commit comments