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

Added developing a microservice section to the existing CRW guide. #694

Merged
merged 2 commits into from
Jul 8, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 108 additions & 3 deletions docs/_guides/codewind-crw-quick-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ title: "Getting Started with Codewind in CodeReady Workspaces"
categories: guides
description: "Use CodeReady Workspaces to develop cloud-native applications from an OpenShift cluster."
permalink: codewind-crw-quick-guide.html
duration: 10 minutes
duration: 15 minutes
keywords: Codewind, CodeReady Workspaces, OpenShift
objectives: ["Install CodeReady Workspaces and Codewind.", "Create a Codewind workspace within CodeReady Workspaces."]
objectives: ["Install CodeReady Workspaces and Codewind.", "Create a Codewind workspace within CodeReady Workspaces.", Develop a simple microservice with the Codewind workspace."]
micgibso marked this conversation as resolved.
Show resolved Hide resolved
icon: images/learn/icon_cloud.svg
---

## Overview

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.

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

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

### Configuring Codewind to use application stacks
Configure Codewind to use Appsody templates so you can focus exclusively on your code. Complete the following steps to select the Appsody templates:

1. Select **Codewind**.
2. Right-click **Projects**.
3. Select **Template Source Manager**.
4. Enable **Appsody Stacks - incubator** and **Default templates**.

After you configured Codewind to use Appsody templates, continue to develop your microservice within Codewind.

### Creating an Appsody project
Throughout the application lifestyle, Appsody helps you develop containerized applications and maximize containers curated for your usage.

1. Under the Explorer pane, select **Codewind**.
2. Expand **Codewind** by clicking the drop-down arrow.
3. Hover over the **Projects** entry underneath Codewind in the Explorer pane, and press the **+** icon to create a project.
* **Note:** Make sure that Docker is running. Otherwise, you get an error.
4. Choose the **Appsody Open Liberty default template (Appsody Stacks - incubator)**.
5. Name your project **appsody-calculator**.
* If you don't see Appsody templates, find and select **Template Source Manager** and enable **Appsody Stacks - incubator**.
* The templates are refreshed, and the Appsody templates are available.
6. Press **Enter**.
* 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.

Your project is complete when you see that your application status is running and your build status is successful.

### Accessing the application endpoint in a browser
1. Return to your project under the **Explorer** pane.
2. Select the Open App icon next to your project's name, or right-click your project and select **Open App**.

Your application is now opened in a browser, showing the welcome to your Appsody microservice page.

### Adding a REST service to your application
1. Go to your project's workspace under the **Explorer** pane.
2. Go to `src`>`main`>`java`>`dev`>`appsody`>`starter`.
3. Right-click **starter** and select **New File**.
4. Create a file, name it `Calculator.java`, and press **Enter**. This file is your JAX-RS resource.
5. Before you input any code, make sure that the file is empty.
6. Populate the file with the following code and then **save** the file:

```java
package dev.appsody.starter;

import javax.ws.rs.core.Application;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import javax.ws.rs.PathParam;

@Path("/calculator")
public class Calculator extends Application {

@GET
@Path("/aboutme")
@Produces(MediaType.TEXT_PLAIN)
public String aboutme() {
return "You can add (+), subtract (-), and multiply (*) with this simple calculator.";
}

@GET
@Path("/{op}/{a}/{b}")
@Produces(MediaType.TEXT_PLAIN)
public Response calculate(@PathParam("op") String op, @PathParam("a") String a, @PathParam("b") String b) {
int numA = Integer.parseInt(a);
int numB = Integer.parseInt(b);

switch (op) {
case "+":
return Response.ok(a + "+" + b + "=" + (Integer.toString((numA + numB)))).build();

case "-":
return Response.ok(a + "-" + b + "=" + (Integer.toString((numA - numB)))).build();

case "*":
return Response.ok(a + "*" + b + "=" + (Integer.toString((numA * numB)))).build();

default:
return Response.ok("Invalid operation. Please Try again").build();
}
}
}
```

Any changes that you make to your code are automatically built and redeployed by Codewind, and you can view them in your browser.

### Working with the example calculator microservice
You now can work with the example calculator microservice.

1. Use the URL that you saw when you first opened the application.
2. Make sure to remove the `< >` symbol in the URL.
3. `<url>/starter/calculator/aboutme`
4. You see the following response:

```
You can add (+), subtract (-), and multiply (*) with this simple calculator.
```

You can also try a few of the sample calculator functions:

* `<url>/starter/calculator/{op}/{a}/{b}`, where you can input one of the available operations `(+, _, *)`, and an integer a, and an integer b.
* So for `<url>/starter/calculator/+/10/3` you see: `10+3=13`.

## What you have learned
Now that you have completed this quick guide, you have learned to:

1. Install CodeReady Workspaces and Codewind.
2. Create a Codewind workspace within CodeReady Workspaces.
3. Develop a simple microservice with the Codewind workspace.

## Next Steps
See other quick guides to learn how to develop with Codewind:
Expand Down