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
+26-8Lines changed: 26 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ chmod +x ./mvnw
50
50
For this exercise we will be adding a new endpoint to handle a simple GET request.
51
51
52
52
- Move to the `src/main/.../DemoController.java` file
53
-
- Start writing the code to handle a simple GET request based on the javadoc comment.
53
+
- Start writing the code to handle a simple GET request based on the javadoc comment.
54
54
- Just press enter and wait a couple of seconds, Copilot will generate the code for you.
55
55
- Alternatively, you can test the Copilot inline feature by pressing `ctrl/⌘ + i`. Then write in the text box the desired behaviour.
56
56
@@ -60,7 +60,6 @@ You can now run the application and then test it with curl.
60
60
2. Test with curl: `curl -v http://localhost:8080/hello?key=world`
61
61
3. If you are using GitHub `Codespaces`, replace localhost:8080 with actual `Codespaces` url.
62
62
63
-
64
63
### Exercise 2: Write a Test Case
65
64
66
65
There is an existing unit test `src/test/.../CopilotDemoApplicationTests.java`, run below command to test it.
@@ -106,7 +105,7 @@ Let's now create a new unit test for the case when no key is provided in the req
106
105
107
106
### Exercise 3: Building more functionalities
108
107
109
-
For this exercise, the code can either but in their own controller, or you can reuse the existing `DemoController.java`.
108
+
For this exercise, reuse the existing `DemoController.java`.
110
109
111
110
Add the following endpoints using the help of Copilot, then also create the unit tests for every new operation. It is pretty easy with Copilot !
112
111
@@ -148,11 +147,17 @@ Add the following endpoints using the help of Copilot, then also create the unit
148
147
> Paste the above information and make it as detailed as possible in the Copilot chat text box.
149
148
> Copilot will use by default the open file as context in order to generate the suggestion.
150
149
150
+
### Exercise 4: Refactor your endpoints
151
+
152
+
In exercise 3, we have created a few endpoints in the `DemoController.java` file. Now let's refactor the code to make it more readable and maintainable by moving those endpoints into separate controllers. With the `DemoController.java` file open, ask Copilot using the chat feature how to refactor those endpoints into separate files.
153
+
154
+
> **_NOTE:_** You can use the `@workspaces` command to give Copilot the context of the structure of the whole repo.
151
155
152
-
### Exercise 4: Building more integrations
156
+
### Exercise 5: Building more integrations
153
157
154
158
We have tried out write coding for a few simple tasks earlier. Now let's explore more complex integrations.
155
159
160
+
> **_NOTE:_** You should follow the same pattern as the previous exercise and create each new endpoint in a separate controllers.
156
161
157
162
-**/tellmeajoke**:
158
163
@@ -197,21 +202,33 @@ We have tried out write coding for a few simple tasks earlier. Now let's explore
197
202
- Return a random country from the array
198
203
- Return the country and its iso code
199
204
200
-
### Exercise 5: Document the code
205
+
### Exercise 6: Adding in Swagger
206
+
207
+
Lets now add in Swagger to the project. This will involve installing the following dependency `springfox-boot-starter`. The version should be `3.0.0`.
208
+
209
+
Ask Copilot how you could achieve this. You can use the `@workspaces` command to give Copilot the context of the structure of the whole repo.
210
+
211
+
### Exercise 7: Refactor the code to follow REST principles
212
+
213
+
At this point in the previous exercises, we created a number of endpoints that are not following REST principles. Let's refactor the code to follow REST principles. You should also update the Swagger documentation, so that each endpoint has a summary and is grouped using tags.
214
+
215
+
Ask Copilot how you could achieve this. You can use the `@workspaces` command to give Copilot the context of the structure of the whole repo.
216
+
217
+
### Exercise 8: Document the code
201
218
202
219
Documenting code is always a boring and painful task. However, we can use Copilot to document it for us. In the chat, ask Copilot to add javadoc to all of your files.
203
220
204
221
You can use `@workspaces` to write documentation for the whole repo.
205
222
206
-
### Exercise 6: Verify Tests
223
+
### Exercise 9: Verify Tests
207
224
208
225
Have you been building your Unit Tests along the way? If not this is the perfect time to take a breather and get Copilot to write some unit tests for you!
209
226
210
227
We will create automated tests to check that the functionality of the previous endpoints is correctly implemented. The tests should be together in the `CopilotDemoApplicationTests.java` file.
211
228
212
229
You can leverage Copilot to run the tests. There is a `/tests` command that you can directly run from Copilot Chat or by selecting the piece of code you want to create tests for and using the Copilot inline feature.
213
230
214
-
### Exercise 7: Create a Dockerfile
231
+
### Exercise 10: Create a Dockerfile
215
232
216
233
Use the Dockerfile provided to create a docker image of the application. There are some comments in the Dockerfile that will help you to complete the exercise.
217
234
@@ -227,10 +244,11 @@ With the previous exercises you have gone through some common activities that de
227
244
228
245
- Create new features in the code
229
246
- Work with external APIs
247
+
- Refactor an existing codebase
230
248
- Create documentation
231
249
- Create tests
232
250
233
-
However, there are many other things that Copilot can helkp you with. Feel free to explore other slash command in the Copilot chat like:
251
+
However, there are many other things that Copilot can help you with. Feel free to explore other slash command in the Copilot chat like:
234
252
235
253
-`/fix`: to fix the problems in your code
236
254
-`/explain`: for Copilot to explain you what the code does
0 commit comments