Get the App
SLTechnology News&Howtos  ›  Development  › 

What features are new in the official version of Forest v1.5.3

Shulou Source: shulou.com Published: 2022-06-03 10:05:55 10月03日 Update

This article is to share with you about the new features in the official version of Forest v1.5.3, which the editor thinks is very practical, so I share it with you to learn. I hope you can get something after reading this article, without saying much, let's take a look at it.

V1.5.3 this version has been released, and many new features have been added in this update, including many major updates.

1. New Forest shortcut interface

In previous versions of Forest, you must first define an interface interface class, which is suitable for most scenarios. But it may seem inappropriate to have quick access to a url. So a shortcut interface has been added in this update, so you don't have to start by defining an interface.

It looks something like this:

/ / Get request / / and accept data String str = Forest.get ("/") .executeAsString () as String type; / / Post request / / and accept MyResult myResult = Forest .post ("/") .execute (MyResult.class) as custom MyResult type / / passing generic parameters through the TypeRefernce reference class / / the response data can be accepted as Result userList = Forest .post ("/") .execute (new TypeReferenceList () {}) as a type with complex generic parameters. / / define various parameters / / and accept Map map = Forest.post ("/") .backend ("okhttp3") / / set the backend to okhttp3 .contentTypeJson () / / set the Content-Type header to application/json .host ("127.0.0.1") / / set the host of the address to 127.0.0.1 in Map type. .port (8080) / / set the port of the address to 8080 .addBody ("a") 1) / add Body entry (key-value pair): a, 1.addBody ("b", 2) / / add Body entry (key-value pair: B, 2.maxRetryCount (3) / / set the maximum number of retries of the request to 3 / / set the onSuccess callback function .onsuccess ((data, req, res)-> {log.info ("success!")) }) / / set the onError callback function .onError ((ex, req, res)-> {log.info ("error!");}) / / set the condition for determining the success of the request. Execute when ((req, res)-> res.noException () & & res.statusOk ()) / / execute and return the Map data type object .executeAsMap ()

two。 Request success condition / retry condition

@ Success comment

First define the implementation class of the SuccessWhen interface

Public class TestSuccessWhen implements SuccessWhen {/ * request success condition * @ param req Forest request object * @ param res Forest response object * @ return is successful * / @ Override public boolean successWhen (ForestRequest req ForestResponse res) {/ / there is no exception and the status code is in the normal range and the status code is not equal to 203 / / of course other conditions can also be written here. For example, obtain business data through res.getData () or res.getConent () / then have more business data to judge whether it is successful return res.noException () & & res.statusOk () & & res.statusCode ()! = 203 }} these are the new features in the official version of Forest v1.5.3. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Success interface condition type version data function parameter object update function new business address more status knowledge article complex practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MariaDB MySQL Shulou Tech Info Shulou Information