noble4cc
V2EX  ›  Java

okhttp 在后端项目中用的多吗?

  •  
  •   noble4cc · Jun 3, 2020 · 7972 views
    This topic created in 2353 days ago, the information mentioned may be changed or developed.

    还是只有安卓在用呢?

    26 replies  •  2021-04-22 20:11:15 +08:00
    jorneyr
    jorneyr
    Jun 3, 2020
    1
    我用了基于 OKHttp 封装的 EasyOKHttp,挺好用的
    PhpBestRubbish
    PhpBestRubbish
    Jun 3, 2020
    2
    EasyOKHttp+1
    Kyle18Tang
    Kyle18Tang
    Jun 3, 2020
    3
    Spring Cloud 里 Zull 和 OpenFeign 都可以使用 OkHttp.
    sagaxu
    sagaxu
    Jun 3, 2020 via Android
    4
    okhttp 性能不高,不适合高流量业务
    yinzhili
    yinzhili
    Jun 3, 2020
    5
    用啊,zuul 和 openfeign 都选了它
    RedSpark
    RedSpark
    Jun 3, 2020
    6
    okhttp 至少比 httpclient4 高
    wujieyuan
    wujieyuan
    Jun 3, 2020
    7
    我一般用 Hutool 工具封装的 HttpUtils, 够用了
    qwerthhusn
    qwerthhusn
    Jun 3, 2020
    8
    感觉用起来比 Apache 的 HttpClient 简单一些,API 啥的比较清晰
    BBCCBB
    BBCCBB
    Jun 3, 2020
    9
    retrofit 后端也可以用, feign 也可以用 okhttp 做 backend,

    想用 feign 的异步 http 功能就不能用 okhttp 了. 一般用 jdk11 自带的 httpclient 或者 apache client 实现真异步 http 请求.
    chendy
    chendy
    Jun 3, 2020
    10
    RestTemplate 已封装,okhttp 和 httpClient 爱用哪个用哪个
    yty2012g
    yty2012g
    Jun 3, 2020
    11
    目前后端有使用的挺多,okHttp3,httpClient4.5,Unirest 都有使用。现在使用的比较多的是 unirest,可能 api 相对简单吧
    kanepan19
    kanepan19
    Jun 3, 2020
    12
    httpclient4.5.2 我们业务很依赖 http 请求,配置复杂,性能要求高
    感觉新项目,或者并不是很依赖 httpclient 的项目可以是用 okHttp
    cjh1095358798
    cjh1095358798
    Jun 3, 2020
    13
    看到朋友用过
    noble4cc
    noble4cc
    OP
    Jun 3, 2020
    14
    @yty2012g 这个 unirest 的 api 支持设置连接池吗?
    zoharSoul
    zoharSoul
    Jun 3, 2020
    15
    多,
    毕竟没啥好的选择, 横竖比被废弃的 httpclient 强啊.
    hantsy
    hantsy
    Jun 3, 2020
    16
    这种客户工具在 Java 中太多了。

    Java 11 中全新的 HttpClient(基于 Java 9 引入的 Flow API)

    Spring 中有 RestTemplate,WebClient ( WebFlux 版本,一样可以用当成工具类用在 WebMvc 中),用于测试目的的 MockMvc,TestRestTemplate,WebTestClient 等。

    一般 Jakarta EE 项目,有 Jaxrs Client,Microprofile Typesafe Rest Client 。Quarkus 还另外提供了 Vertx 的 WebClient.

    https://github.com/hantsy/quarkus-sample

    Holidon 也提供自己的 WebClient 。

    https://github.com/hantsy/helidon-sample/tree/master/se-webclient
    hantsy
    hantsy
    Jun 3, 2020
    17
    至于 Okhttp, Apache HttpClient, unirest 这种底层的工具类在开发过程中,我很少用到。
    MoHen9
    MoHen9
    Jun 3, 2020 via Android
    18
    okhttp+retrofit+rxjava 用起来真的特别爽,反正我一直这么用,但后台调用远程接口的场景其实并不多,我调用算法接口用的是 okhttp 。
    zzl22100048
    zzl22100048
    Jun 3, 2020 via iPhone
    19
    非微服务,我就用 resteasyclient
    微服务用 feign
    hantsy
    hantsy
    Jun 3, 2020
    20
    @zzl22100048 Resteasy 现在支持现在的 Jaxrs Client (是 Jaxrs 2.0 后规范的一部分),也支持类似 Microprofile RestClient 接口方式调用。

    https://github.com/hantsy/signup-app/blob/master/src/test/java/org/company/test/rest/RESTTest.java

    很多年前写测试经常用,在使用 Resteasy 的项目中,现在我用 Jaxrs Client 更多一些。feign 和 Microprofile RestClient 的灵感可能与 Resteasy 有关(没有查证),Resteasy 这种方式出现很早了,差不多 10 年了。
    AJQA
    AJQA
    Jun 3, 2020 via Android
    22
    @hantsy 你还有没有在 upwork 接活 还是固定客户?
    hantsy
    hantsy
    Jun 3, 2020
    23
    @virtuemartx 好久没接 Upwork 了。这两年被家里事情搞得一踏糊涂,现在重新开始。
    hantsy
    hantsy
    Jun 3, 2020
    24
    https://github.com/hantsy/signup-app

    @virtuemartx 上面这个链接提到的项目是以前一个 Freelance 项目,客户公开代码的。1500USD 。
    emacsistyzy
    emacsistyzy
    Apr 22, 2021
    25
    @sagaxu 高流量业务一般用什么?
    sagaxu
    sagaxu
    Apr 22, 2021 via Android
    26
    @emacsistyzy vertx-web-client 或者其它支持异步的 http 库
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1270 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 94ms · UTC 17:23 · PVG 01:23 · LAX 09:23 · JFK 12:23
    ♥ Do have faith in what you're doing.