Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit 49b7819

Browse files
authored
Merge pull request #694 from j-c-berger/jcberger_3202_CRWaddon
Added developing a microservice section to the existing CRW guide.
2 parents 214c505 + 2711104 commit 49b7819

File tree

1 file changed

+108
-3
lines changed

1 file changed

+108
-3
lines changed

docs/_guides/codewind-crw-quick-guide.md

Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ title: "Getting Started with Codewind in CodeReady Workspaces"
55
categories: guides
66
description: "Use CodeReady Workspaces to develop cloud-native applications from an OpenShift cluster."
77
permalink: codewind-crw-quick-guide.html
8-
duration: 10 minutes
8+
duration: 15 minutes
99
keywords: Codewind, CodeReady Workspaces, OpenShift
10-
objectives: ["Install CodeReady Workspaces and Codewind.", "Create a Codewind workspace within CodeReady Workspaces."]
10+
objectives: ["Install CodeReady Workspaces and Codewind.", "Create a Codewind workspace within CodeReady Workspaces.", "Develop a simple microservice with the Codewind workspace."]
1111
icon: images/learn/icon_cloud.svg
1212
---
1313

1414
## Overview
15-
1615
Use Eclipse Codewind to develop microservice applications from application stacks in an integrated developer environment (IDE). CodeReady Workspaces provides a containerized IDE for cloud-native application development on an OpenShift cluster.
1716

1817
## Developing with CodeReady Workspaces
@@ -124,11 +123,117 @@ After you set up Codewind, log in to your CodeReady Workspaces account and creat
124123

125124
6\. Click **Create & Open**.
126125

126+
### Configuring Codewind to use application stacks
127+
Configure Codewind to use Appsody templates so you can focus exclusively on your code. Complete the following steps to select the Appsody templates:
128+
129+
1. Select **Codewind**.
130+
2. Right-click **Projects**.
131+
3. Select **Template Source Manager**.
132+
4. Enable **Appsody Stacks - incubator** and **Default templates**.
133+
134+
After you configured Codewind to use Appsody templates, continue to develop your microservice within Codewind.
135+
136+
### Creating an Appsody project
137+
Throughout the application lifestyle, Appsody helps you develop containerized applications and maximize containers curated for your usage.
138+
139+
1. Under the Explorer pane, select **Codewind**.
140+
2. Expand **Codewind** by clicking the drop-down arrow.
141+
3. Hover over the **Projects** entry underneath Codewind in the Explorer pane, and press the **+** icon to create a project.
142+
* **Note:** Make sure that Docker is running. Otherwise, you get an error.
143+
4. Choose the **Appsody Open Liberty default template (Appsody Stacks - incubator)**.
144+
5. Name your project **appsody-calculator**.
145+
* If you don't see Appsody templates, find and select **Template Source Manager** and enable **Appsody Stacks - incubator**.
146+
* The templates are refreshed, and the Appsody templates are available.
147+
6. Press **Enter**.
148+
* To monitor your project's progress, right-click your project, and select **Show all logs**. Then, an **Output** tab is displayed where you see your project's build logs.
149+
150+
Your project is complete when you see that your application status is running and your build status is successful.
151+
152+
### Accessing the application endpoint in a browser
153+
1. Return to your project under the **Explorer** pane.
154+
2. Select the Open App icon next to your project's name, or right-click your project and select **Open App**.
155+
156+
Your application is now opened in a browser, showing the welcome to your Appsody microservice page.
157+
158+
### Adding a REST service to your application
159+
1. Go to your project's workspace under the **Explorer** pane.
160+
2. Go to `src`>`main`>`java`>`dev`>`appsody`>`starter`.
161+
3. Right-click **starter** and select **New File**.
162+
4. Create a file, name it `Calculator.java`, and press **Enter**. This file is your JAX-RS resource.
163+
5. Before you input any code, make sure that the file is empty.
164+
6. Populate the file with the following code and then **save** the file:
165+
166+
```java
167+
package dev.appsody.starter;
168+
169+
import javax.ws.rs.core.Application;
170+
import javax.ws.rs.GET;
171+
import javax.ws.rs.Path;
172+
import javax.ws.rs.Produces;
173+
import javax.ws.rs.core.MediaType;
174+
import javax.ws.rs.core.Response;
175+
176+
import javax.ws.rs.PathParam;
177+
178+
@Path("/calculator")
179+
public class Calculator extends Application {
180+
181+
@GET
182+
@Path("/aboutme")
183+
@Produces(MediaType.TEXT_PLAIN)
184+
public String aboutme() {
185+
return "You can add (+), subtract (-), and multiply (*) with this simple calculator.";
186+
}
187+
188+
@GET
189+
@Path("/{op}/{a}/{b}")
190+
@Produces(MediaType.TEXT_PLAIN)
191+
public Response calculate(@PathParam("op") String op, @PathParam("a") String a, @PathParam("b") String b) {
192+
int numA = Integer.parseInt(a);
193+
int numB = Integer.parseInt(b);
194+
195+
switch (op) {
196+
case "+":
197+
return Response.ok(a + "+" + b + "=" + (Integer.toString((numA + numB)))).build();
198+
199+
case "-":
200+
return Response.ok(a + "-" + b + "=" + (Integer.toString((numA - numB)))).build();
201+
202+
case "*":
203+
return Response.ok(a + "*" + b + "=" + (Integer.toString((numA * numB)))).build();
204+
205+
default:
206+
return Response.ok("Invalid operation. Please Try again").build();
207+
}
208+
}
209+
}
210+
```
211+
212+
Any changes that you make to your code are automatically built and redeployed by Codewind, and you can view them in your browser.
213+
214+
### Working with the example calculator microservice
215+
You now can work with the example calculator microservice.
216+
217+
1. Use the URL that you saw when you first opened the application.
218+
2. Make sure to remove the `< >` symbol in the URL.
219+
3. `<url>/starter/calculator/aboutme`
220+
4. You see the following response:
221+
222+
```
223+
You can add (+), subtract (-), and multiply (*) with this simple calculator.
224+
```
225+
226+
You can also try a few of the sample calculator functions:
227+
228+
* `<url>/starter/calculator/{op}/{a}/{b}`, where you can input one of the available operations `(+, _, *)`, and an integer a, and an integer b.
229+
* So for `<url>/starter/calculator/+/10/3` you see: `10+3=13`.
230+
127231
## What you have learned
128232
Now that you have completed this quick guide, you have learned to:
129233

130234
1. Install CodeReady Workspaces and Codewind.
131235
2. Create a Codewind workspace within CodeReady Workspaces.
236+
3. Develop a simple microservice with the Codewind workspace.
132237

133238
## Next Steps
134239
See other quick guides to learn how to develop with Codewind:

0 commit comments

Comments
 (0)