Forest is a declarative Java open source HTTP framework, which is more concise and easier to understand and maintain than its predecessors Httpclient and OkHttp

Not much nonsense, let us first look at what the code written by Kangkang looks like


public interface AmapClient {

    /**
     * 聪明的你一定看出来了这是一个GET请求
     */
    @Get("http://ditu.amap.com/service/regeo?longitude={lng}&latitude={lat}")
    Map getLocation(@Var("lng") String longitude, @Var("lat") String latitude);
}

It is easy to complete the Rest API interface definition for obtaining the geographical information of the latitude and longitude from the Gaode map, and then just callAmapClient.getLocationThis Java method can automatically send an HTTP request, accept the response data, and then convert it into a Map type object and hand it over to you

This is indeed many times better than manually assembling OkHttp Client objects and OkRequest objects before. Even if there are many HTTP interfaces to call and the structure is complex, don’t be afraid

But when there are tens of thousands of HTTP requests to be called in a project, the management and maintenance costs of the interface will also rise to a difficult level

For example, which interface corresponds to which website platform and which URL is often not easy to see at a glance, and the specific interfaces scattered in the project cannot be known at once.

Another problem is that the placeholders in the template string in Forest can conveniently refer to the variables defined in the configuration file through@VarTags define parameters, but syntax highlighting and basic support for an expression language application (such as code completion and hints)

This is not a problem when the code is small. The code interface is hidden to a certain extent, and the probability of variable references in the string template is greatly increased. Because there are too many configurations, it is easy to figure out who will call whom.

At this time, we invite our protagonist ForestX to appear~~

IDEA plug-in tailored for Forest

ForestX is an IDEA plugin that supports Forest

It can greatly improve your development experience when using the Forest framework

Warehouse address: https://gitee.com/CHMing7/ForestX

Next, let us know what functions it has:

Side Navigation Toolbar

Click on the rightForestLogo bird icon, can be openedForestXnavigation toolbar, it will list all the Forest interfaces defined in the project together for easy management

tools-window.gif

  • The interface list is divided into three levels: the top-level project (directory), Forest interface (bird icon), request method
  • In the Forest interface list, the icon to the left of the method name represents the type of the request (GET/POST)
  • The right side of the method name/interface is the URL path displayed in gray font (generally not the full path, but the path defined on the method)

code completion

  1. According to the configuration fileforest.variablesDefined global variables to complete the code

completion-global-variables.gif

  1. Complete the code according to the YAML configuration items defined in the YAML configuration file

completion-yaml.gif

  1. by request method@VarParameter definitions to complete the code

completion-var-parameter.gif

  1. according to@BindingVarAnnotate defined methods to complete the code

completion-BindingVar.gif

  1. In programmatic code, intelligent prompts for code completion can also appear

But currently only for Forest.get,Forest.post Wait for the request method to open the secondary function

completion-forest-api.gif

code jump

hold down the keyboardCtrlkey, move the mouse to an identifier (such as a variable name) in a Forest template expression, and hover for a short period of time, a brief information about the configuration variable or Java property referenced by the identifier will pop up

Click the left mouse button at this time to jump to the definition code of the variable/configuration referenced by the identifier

epilogue

The job of programmers is to create tools, and tools can also be used to serve programmers. This is a positive cycle and the epitome of iterations. It is in iterations that programmers continue to create many A better, better, more world-changing tool

And the iteration of ForestX has just begun!

#Forest #IDEA #Double #fun #ForestX #News Fast Delivery

Leave a Comment

Your email address will not be published. Required fields are marked *