Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report