Spring 6 Rest客户端 webClient--HTTP Interface

Spring.io Doc

REST Clients

The Spring Framework provides the following choices for making calls to REST endpoints:

  • WebClient - non-blocking, reactive client w fluent API.

  • HTTP Interface - annotated interface with generated, dynamic proxy implementation.

webClient

WebClient-非阻塞、反应式客户端流畅的 API

WebClient 是一个非阻塞的反应式客户端,用于执行 HTTP 请求。它是在5.0中引入的,提供了 RestTemplate 的替代方案,支持同步、异步和流场景。

WebClient 支持以下内容:

  • Non-blocking I/O.

  • Reactive Streams back pressure.

  • High concurrency with fewer hardware resources.

  • Functional-style, fluent API that takes advantage of Java 8 lambdas.

  • Synchronous and asynchronous interactions.

  • Streaming up to or streaming down from a server.

HTTP Interface

第一,使用@HttpExchange 方法声明一个接口:

@GetExchange("/repos/{owner}/{repo}") 需要http请求的接口

Repository 是自定义实体类用来收集数据

第二,创建一个代理来执行声明的 HTTP 交换:

可以这么理解

@ HttpExchange 在适用于所有方法的类型级别得到支持:

# HttpInterface Windows上C++封装的HTTP库,包含三种实现模式(WinInet、WinHttp、socket) 主要实现了HTTP的get\post方法,下载到内存、下载到本地文件,回调下载进度等接口 测试程序中展现了常用的几个方法。 接口类声明: class IHttpBase { public: virtual void SetDownloadCallback(IHttpCallback* pCallback, void* pParam)= 0; virtual bool DownloadFile(LPCWSTR lpUrl, LPCWSTR lpFilePath)= 0; virtual bool DownloadToMem(LPCWSTR lpUrl, OUT void** ppBuffer, OUT int* nSize)= 0; virtual void FreeInstance()= 0; virtual HttpInterfaceError GetErrorCode()= 0; }; //////////////////////////////////////////////////////////////////////////////////// //HTTP请求接口类 class IWininetHttp :public IHttpBase { public: //HTTP请求功能 virtual string Request(LPCSTR lpUrl, HttpRequest type, LPCSTR lpPostData = NULL, LPCSTR lpHeader = NULL)= 0; virtual string Request(LPCWSTR lpUrl, HttpRequest type, LPCSTR lpPostData = NULL, LPCWSTR lpHeader = NULL)= 0; }; /////////////////////////////////////////////////////////////////////////////////////// //HTTP socket类 class ISocketHttp :public IHttpBase { public: virtual LPCWSTR GetIpAddr()const= 0; }; /////////////////////////////////////////////////////////////////////////////////////// //WinHttp类 class IWinHttp : public IWininetHttp { public: //设置超时时间,单位:毫秒 virtual void SetTimeOut(int dwConnectTime, int dwSendTime, int dwRecvTime)= 0; }; 能力有限,有bug欢迎指正 email:jelinyao@163.com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值