You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 14
Next »
Intro
Since you develop API you need endpoints and controllers. Endpoint is a point at which an API (the code that allows two software programs to communicate with each other) connects with the software program. Due to writing an endpoint is a routine, JBT allows to reduce boilerplate code. Controller's main aim is to accept an input and to convert it to commands for the model or view. Since you work with API, view is an endpoint.
JBT uses XML-files for describing controllers, endpoints and models. Then it uses such files for Java-code generation. As a result you get API based on MVC pattern written on Java. Let's start
Structure
API structure is:

api-impl
this module contains project controllers. Here example is an example of api-impl structure:

Controller example is given below:
package com.knubisoft.api.impl;
import com.knubisoft.api.dto.GenericApiResponse;
import com.knubisoft.api.dto.JwtTokensResponse;
import com.knubisoft.api.dto.LoginRequest;
import com.knubisoft.api.spec.LoginAPI;
import com.knubisoft.service.LoginService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
@RequiredArgsConstructor
@RestController
public class LoginAPIImpl implements LoginAPI {
private final LoginService loginService;
@Override
public ResponseEntity<GenericApiResponse<JwtTokensResponse>> login(@Valid final LoginRequest requestBody) {
final JwtTokensResponse result = loginService.login(requestBody.getUsername(), requestBody.getPassword());
return ResponseEntity.ok(new GenericApiResponse<>(result));
}
}
api-spec
this module consists of xml description of enpoints, controllers, enums, dto and generated API interfaces
About xml description you can find details here