Skip to content

Files

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Latest commit

0e4337b · Feb 16, 2022

History

History
79 lines (57 loc) · 2.52 KB

index.asciidoc

File metadata and controls

79 lines (57 loc) · 2.52 KB

Develop a Devon4j HTTP REST Service

technology=java;http;spring data;jpa;flyway;cxf;jax-rs

difficulty=intermediate

topic=rest;rest api;authentication;api;client

asset=devon4j;mythaystar

Prerequisites

  • User should have development experience in Java programming.

  • Basic knowledge of REST.

  • Get the devonfw-ide

Learning Goal

In this tutorial, you will learn how to implement a simple REST service.

REST (REpresentational State Transfer) is an inter-operable protocol for services that is more lightweight than SOAP.

First of all, we should get the devonfw-ide loaded.

restoreDevonfwIde(["java", "vscode"])

Create the devon4j REST Service

In this step, we will see how to implement a REST service in a devon4j project.

First of all, we must create a devon4j project to work with.

createDevon4jProject("com.example.application.httprestservice")

Once the project is created, we will start building the application.

In the files folder, there are some Java files that will be needed in the application development.

We need to copy them into the project as follows:

createFile("httprestservice/core/src/main/java/com/example/application/httprestservice/visitormanagement/service/impl/rest/VisitormanagementRestServiceImpl.java", "files/VisitormanagementRestServiceImpl.java") createFile("httprestservice/core/src/main/java/com/example/application/httprestservice/visitormanagement/service/impl/rest/VisitormanagementRestService.java", "files/VisitormanagementRestService.java")

Here , you can see "VisitormanagementRestServiceImpl.java" is annotated with @Named to make it a spring-bean. To get return response to client "returnResponseToClient()" can be accessed via HTTP GET under the URL path "/visitormanagement/v1/clientrequest". It will return its result (String) as JSON (see @Produces in VisitormanagementRestService).

Then, we can launch the application and do GET requests.

changeFile("httprestservice/core/src/main/resources/application.properties", { "file": "files/server_application.txt" }) changeFile("httprestservice/core/src/main/resources/config/application.properties", { "file": "files/server_config_application.txt" }) buildJava("httprestservice", false)

runServerJava("httprestservice/server", { "startupTime": 1000, "port": 8081, "path": "httprestservice" })