technology=java;http;spring data;jpa;flyway;cxf;jax-rs
difficulty=intermediate
topic=rest;rest api;authentication;api;client
asset=devon4j;mythaystar
-
User should have development experience in Java programming.
-
Basic knowledge of REST.
-
Get the devonfw-ide
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"])
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" })