Skip to content

Commit cb548ae

Browse files
lioncfliubochencwx
authored andcommitted
docs: update content of http/grpc's development guide
1 parent 52b447d commit cb548ae

10 files changed

+44
-56
lines changed

docs/en/grpc_protocol_client.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ accessing a tRPC service:
2727

2828
## Call process
2929

30-
* Get the `XxServiceProxyPtr` object `proxy`: use the `GetClient()->GetProxy<XxServiceProxy>(...)`.
30+
* Get the `XxServiceProxyPtr` object `proxy`: use the `GetTrpcClient()->GetProxy<XxServiceProxy>(...)`.
3131

3232
```cpp
3333
auto proxy = ::trpc::GetTrpcClient()->GetProxy<::trpc::test::helloworld::GreeterServiceProxy>("xx_service_name")
@@ -84,9 +84,8 @@ Use the synchronous or asynchronous interface corresponding to the selected runt
8484
::trpc::test::helloworld::HelloRequest req;
8585
req.set_msg("future");
8686
bool succ = true;
87-
::trpc::Latch latch(1);
88-
proxy->AsyncSayHello(client_ctx, req)
89-
.Then([&latch, &succ](::trpc::Future<::trpc::test::helloworld::HelloReply>&& fut) {
87+
auto fut = proxy->AsyncSayHello(client_ctx, req)
88+
.Then([&succ](::trpc::Future<::trpc::test::helloworld::HelloReply>&& fut) {
9089
if (fut.IsReady()) {
9190
auto rsp = fut.GetValue0();
9291
std::cout << "get rsp msg: " << rsp.msg() << std::endl;
@@ -95,10 +94,8 @@ Use the synchronous or asynchronous interface corresponding to the selected runt
9594
succ = false;
9695
std::cerr << "get rpc error: " << exception.what() << std::endl;
9796
}
98-
latch.count_down();
9997
return ::trpc::MakeReadyFuture<>();
10098
});
101-
latch.wait();
10299
return succ ? 0 : -1;
103100
}
104101
```

docs/en/http_protocol_client.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Next, let's take a look at the steps to access an HTTP service.
6262

6363
### Basic steps to access an HTTP service
6464

65-
1. Get the `HttpServiceProxyPtr` object `proxy`: use `GetClient()->GetProxy<HttpServiceProxy>(...)`.
65+
1. Get the `HttpServiceProxyPtr` object `proxy`: use `GetTrpcClient()->GetProxy<HttpServiceProxy>(...)`.
6666
2. Create the `ClientContextPtr` object `context`: use `MakeClientContext(proxy)`.
6767
3. Call the expected API to access and check the return code, such as `GetString` or `PostString` (we can choose to use
6868
synchronous or asynchronous interfaces based on your business scenario).
@@ -84,7 +84,7 @@ Example: [http_client.cc](../../examples/features/http/client/client.cc)
8484
auto proxy = ::trpc::GetTrpcClient()->GetProxy<::trpc::http::HttpServiceProxy>(servie_name, option);
8585
```
8686

87-
> There are two ways to create an `HttpServiceProxyPtr`:
87+
> There are three ways to create an `HttpServiceProxyPtr`:
8888
>
8989
> -1- Set the `ServiceProxyOption` object.
9090
>
@@ -142,11 +142,11 @@ Note: The Get2 below is just an interface name and does not use the HTTP2 protoc
142142

143143
| Class/Object | Interface Name | Functionality | Parameters | Return Value | Remarks |
144144
|------------------|----------------------------------------------------------------------------------------------------------|------------------------------------------------------------|------------------------------------------------------------------------------------------|--------------------------------|------------------------|
145-
| HttpServiceProxy | Status Get(const ClientContextPtr&amp; context, const std::string&amp; url, rapidjson::Document* json) | Obtains a JSON response message using GET | client context<br> url resource location <br> json stores the response message | Status | Synchronous interface |
146-
| HttpServiceProxy | Status GetString(const ClientContextPtr&amp; context, const std::string&amp; url, std::string* rspStr) | Obtains a string response message using GET | client context<br> url resource location <br> rspStr stores the response message | Status | Synchronous interface |
147-
| HttpServiceProxy | Status Get2(const ClientContextPtr&amp; context, const std::string&amp; url, HttpResponse* rsp) | Obtains an HTTP response using GET | client context<br> url resource location <br> rsp stores the HTTP response | Status | Synchronous interface |
148-
| HttpServiceProxy | Future&lt;rapidjson::Document> AsyncGet(const ClientContextPtr&amp; context, const std::string&amp; url) | Obtains a JSON response message using GET asynchronously | client context<br> url resource location | Future&lt;rapidjson::Document> | Asynchronous interface |
149-
| HttpServiceProxy | Future&lt;std::string> AsyncGetString(const ClientContextPtr&amp; context, const std::string&amp; url) | Obtains a string response message using GET asynchronously | client context<br> url resource location | Future&lt;std::string> | Asynchronous interface |
145+
| HttpServiceProxy | Status Get(const ClientContextPtr&amp; context, const std::string&amp; url, rapidjson::Document* json) | Obtains a JSON response message using GET | context client context<br> url resource location <br> json stores the response message | Status | Synchronous interface |
146+
| HttpServiceProxy | Status GetString(const ClientContextPtr&amp; context, const std::string&amp; url, std::string* rspStr) | Obtains a string response message using GET | context client context<br> url resource location <br> rspStr stores the response message | Status | Synchronous interface |
147+
| HttpServiceProxy | Status Get2(const ClientContextPtr&amp; context, const std::string&amp; url, HttpResponse* rsp) | Obtains an HTTP response using GET | context client context<br> url resource location <br> rsp stores the HTTP response | Status | Synchronous interface |
148+
| HttpServiceProxy | Future&lt;rapidjson::Document> AsyncGet(const ClientContextPtr&amp; context, const std::string&amp; url) | Obtains a JSON response message using GET asynchronously | context client context<br> url resource location | Future&lt;rapidjson::Document> | Asynchronous interface |
149+
| HttpServiceProxy | Future&lt;std::string> AsyncGetString(const ClientContextPtr&amp; context, const std::string&amp; url) | Obtains a string response message using GET asynchronously | context client context<br> url resource location | Future&lt;std::string> | Asynchronous interface |
150150
| HttpServiceProxy | Future&lt;HttpResponse> AsyncGet2(const ClientContextPtr&amp; context, const std::string&amp; url) | Obtains an HTTP response using GET asynchronously | context client context<br> url resource location | Future&lt;HttpResponse> | Asynchronous interface |
151151

152152
Translation:
@@ -507,7 +507,7 @@ be transmitted correctly.
507507
If you only need to get the status code of 2xx, you can use the interface that returns `HttpResponse*`.
508508
If you need to get the status code of non-2xx, please override the `CheckHttpResponse(...)` method.
509509

510-
## Does the `target` configuration item in the configuration file support the `domain:Port` format?
510+
## Does the `target` configuration item in the configuration file support the `domain:port` format?
511511

512512
Yes, it is supported. You need to:
513513

docs/en/http_protocol_service.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
# Overview
44

55
Currently, tRPC-Cpp supports two types of HTTP services: HTTP Standard Service and HTTP RPC Service (these names are
6-
used to
7-
differentiate between the two services).
6+
used to differentiate between the two services).
87

98
> HTTP standard service: It is a regular HTTP service that does not use proto files to define the service interface.
109
> Users need to write their own code to define the service interface and register URL routes.
@@ -160,7 +159,7 @@ Basic steps:
160159
After the application is started, we can access it through the following URLs.
161160

162161
```bash
163-
# GET /foo HTTP1.1
162+
# GET /foo HTTP/1.1
164163
# e.g: curl http://$ip:$port/foo
165164
$ hello world!
166165
```
@@ -474,7 +473,7 @@ class ApiUserHandler : public ::trpc::http::HttpHandler {
474473

475474
#### Register `HttpController`
476475

477-
Using the `HTTP_HANDLER` macro, users can easily register `Controller`-like interfaces to the route:
476+
Using the `TPRC_HTTP_HANDLER` macro, users can easily register `Controller`-like interfaces to the route:
478477

479478
Note: `Controller` does not inherit the `HttpHandler` class, but only has the same interface signature.
480479

docs/en/http_protocol_upload_download_client.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ transfer `Transfer-Encoding: chunked`.
2222

2323
*Note: The synchronous streaming interface needs to run in the `fiber` coroutine environment.*
2424

25-
## Programming interfaces synchronous streaming
25+
## Programming interfaces about synchronous streaming
2626

2727
### Client stream reader writer by synchronous
2828

@@ -91,7 +91,7 @@ Taking the Read interface as an example, tRPC provides two types of specific int
9191
Example: [upload_client.cc](../../examples/features/http_upload_download/client/upload_client.cc)
9292

9393
The basic data uploading process involves the following steps: setting the length form/chunked form, sending the request
94-
header, reading the response header, writing data, and completing the write.
94+
header, writing data, completing the write, and reading the response header.
9595

9696
* **Setting the length form/chunked form**
9797

@@ -101,17 +101,17 @@ header, reading the response header, writing data, and completing the write.
101101

102102
The client does not need to send the request header. tRPC does not provide this method. When the stream is obtained, tRPC-Cpp has already sent the request header.
103103

104-
* **Reading the response header**
105-
106-
If the ReadHeaders interface is executed successfully, it means that the response header from the server has been received. The HTTP status code (200, 404, etc.) can be obtained from the http_code parameter. These constants are also defined in tRPC, such as ResponseStatus::kOk. The response header can be obtained from the http_header parameter.
107-
108104
* **Writing data**
109105

110106
The user can continuously send data fragments to the server through the Write interface. If the user is using chunked form, there is no need to encode the transmitted data with chunked. tRPC will handle it automatically. If the user is using length form, the Write interface will report the kStreamStatusClientWriteContentLengthError error if the data sent by the user exceeds the set length.
111107

112108
* **Completing the write**
113109

114110
The user informs the reader/writer that all data has been sent through the WriteDone interface. If the user is using chunked form, the framework will send the chunked end flag to the server. If the user is using length form, the framework will check whether the length of the data sent by the user is consistent with the set length. If they are inconsistent, the kStreamStatusClientWriteContentLengthError error will be reported. Once the WriteDone interface is called, the user should not try to use the Write interface again.
111+
112+
* **Reading the response header**
113+
114+
If the ReadHeaders interface is executed successfully, it means that the response header from the server has been received. The HTTP status code (200, 404, etc.) can be obtained from the http_code parameter. These constants are also defined in tRPC, such as ResponseStatus::kOk. The response header can be obtained from the http_header parameter.
115115

116116
* Example code
117117

@@ -293,10 +293,10 @@ Call `GetAsyncStreamReaderWriter` of `HttpStreamProxy` to obtain the stream read
293293
| Future&lt;NoncontiguousBuffer> ReadAtMost(uint64_t len, int timeout = max) | Can be called in both length mode and chunk mode, and gets up to len length of data. </br>If the size of the data received from the network is smaller than len, return data of size. </br>If the size of the data received from the network is larger than len, return data of length len. </br>If the buffer is empty, it means EOF.</br>Scenario 1: Used in memory-limited situations, limiting the maximum read length each time.</br>Scenario 2: In relay mode, it can obtain data in a timely manner and send it downstream. | len in bytes, timeout (ms) |
294294
| Future&lt;NoncontiguousBuffer> ReadExactly(uint64_t len, int timeout = max) | Can be called in both length mode and chunk mode, and gets fixed length data of len. If EOF is read, it returns as much data as there is in the network. </br>If the size of the buffer read is smaller than len, it means EOF.</br>Special scenario 1: The requested data is compressed in fixed size and needs to be read in fixed size for decompression. | len in bytes, timeout (ms) |
295295

296-
* Client-side interfaces for writing complete requests and reading complete responses:
296+
* Client-side interfaces for writing complete requests and reading complete responses:
297297

298-
| Interface Signature | Function | Parameters |
299-
|---------------------------------------------------------------------------------------------------------|---------------------------------------------|----------------------------------------------------|
300-
| Future<> WriteFullRequest(HttpClientAsyncStreamWriterPtr rw, HttpRequest&& req) | Writes the complete request to the stream | rw: Client-side stream reader/writer, timeout (ms) |
301-
| Future&lt;HttpResponsePtr> ReadFullResponse(HttpClientAsyncStreamReaderWriterPtr rw, int timeout = max) | Reads the complete response from the stream | rw: Client-side stream reader/writer, timeout (ms) |
298+
| Interface Signature | Function | Parameters |
299+
|---------------------------------------------------------------------------------------------------------|---------------------------------------------|----------------------------------------------------|
300+
| Future<> WriteFullRequest(HttpClientAsyncStreamWriterPtr rw, HttpRequest&& req) | Writes the complete request to the stream | rw: Client-side stream reader/writer, timeout (ms) |
301+
| Future&lt;HttpResponsePtr> ReadFullResponse(HttpClientAsyncStreamReaderWriterPtr rw, int timeout = max) | Reads the complete response from the stream | rw: Client-side stream reader/writer, timeout (ms) |
302302

docs/en/http_protocol_upload_download_service.md

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
# Overview
44

5-
Topic: How to develop an HTTP file upload-download service based on tRPC-Cpp.
6-
75
In HTTP services, there are scenarios where large files need to be read or sent. Reading the entire file into memory is
86
inefficient and puts a lot of pressure on the memory, making it difficult to upload large files. tRPC-Cpp provides a set
97
of HTTP streaming read and write data chunking interfaces, which can receive and send large files in chunks.

docs/zh/grpc_protocol_client.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ Unary Service:可以理解为一问一答服务,是为了区别流式服务
8383
::trpc::test::helloworld::HelloRequest req;
8484
req.set_msg("future");
8585
bool succ = true;
86-
::trpc::Latch latch(1);
87-
proxy->AsyncSayHello(client_ctx, req)
88-
.Then([&latch, &succ](::trpc::Future<::trpc::test::helloworld::HelloReply>&& fut) {
86+
auto fut = proxy->AsyncSayHello(client_ctx, req)
87+
.Then([&succ](::trpc::Future<::trpc::test::helloworld::HelloReply>&& fut) {
8988
if (fut.IsReady()) {
9089
auto rsp = fut.GetValue0();
9190
std::cout << "get rsp msg: " << rsp.msg() << std::endl;
@@ -94,10 +93,8 @@ Unary Service:可以理解为一问一答服务,是为了区别流式服务
9493
succ = false;
9594
std::cerr << "get rpc error: " << exception.what() << std::endl;
9695
}
97-
latch.count_down();
9896
return ::trpc::MakeReadyFuture<>();
9997
});
100-
latch.wait();
10198
return succ ? 0 : -1;
10299
}
103100
```

docs/zh/http_protocol_client.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ tRPC-Cpp 默认支持 tRPC 协议,同时也支持 HTTP 协议。
77
RPC 服务。
88
这可以使一个 RPC 服务同时支持 tRPC 和 HTTP 协议,当前支持通过 HTTP 客户端访问 tRPC 服务。
99

10-
本文介绍如何基于 tRPC-Cpp (下面简称 tRPC)访问 HTTP 服务,开发可以了解到如下内容
10+
本文介绍如何基于 tRPC-Cpp (下面简称 tRPC)访问 HTTP 服务,开发者可以了解到如下内容
1111

1212
* 访问 HTTP 标准服务
1313
* 快速上手:使用一个 HTTP Client 访问 HTTP 服务。
@@ -228,7 +228,7 @@ tRPC-Cpp 侧暂未实现 HTTP CONNECT 相关逻辑。
228228

229229
tRPC 当前支持 `HTTP/1.1``HTTP 1.0`, 默认使用 `HTTP/1.1`。暂未支持 `HTTP/2.0`,在准备中。
230230

231-
如果使用使用 1.0 ,可以使用如下方法设置。
231+
如果使用 1.0 ,可以使用如下方法设置。
232232

233233
```cpp
234234
request.SetVersion("1.0");
@@ -481,7 +481,7 @@ curl -H 'trpc-trans-info: {"k1": "v1", "k2": "v2" }' -T xx.seriealized.pb $url
481481
如果只需要获取 2xx 的状态码,可直接使用返回为 `HttpResponse*` 的接口。
482482
如果需要获取非 2xx 的状态码,请 override `CheckHttpResponse(...)` 方法。
483483

484-
## 配置文件中的 `target` 配置项是否支持 `域名:Port` 格式?
484+
## 配置文件中的 `target` 配置项是否支持 `domain:port` 格式?
485485

486486
支持的,需要:
487487

docs/zh/http_protocol_service.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
本文介绍如何基于 tRPC-Cpp (下面简称 tRPC)开发 [HTTP](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol)
1111
服务,开发者可以了解到如下内容:
1212

13-
* 如何开发 HTTP 标准服务
13+
* 如何开发 HTTP 标准服务
1414
* 快速上手:快速搭建一个 HTTP 服务。
1515
* 功能特性一览:RESTful;HTTPS。
1616
* 基础用法:获取请求、响应常用接口;配置请求路由规则。
@@ -110,7 +110,7 @@ class FooHandler : public ::trpc::http::HttpHandler {
110110
接口签名大致如下:
111111
112112
```cpp
113-
class trpc::http::HttpHandler {
113+
class HttpHandler {
114114
public:
115115
virtual ::trpc::Status Head(const ::trpc::ServerContextPtr& ctx, const ::trpc::http::RequestPtr& req, ::trpc::http::Response* rsp);
116116
virtual ::trpc::Status Get(const ::trpc::ServerContextPtr& ctx, const ::trpc::http::RequestPtr& req, ::trpc::http::Response* rsp);
@@ -155,7 +155,7 @@ class HttpdServer : public ::trpc::TrpcApp {
155155
应用程序启动后,可以通过如下如下 URL 访问。
156156

157157
```bash
158-
# GET /foo HTTP1.1
158+
# GET /foo HTTP/1.1
159159
# e.g: curl http://$ip:$port/foo
160160
$ hello world!
161161
```
@@ -523,7 +523,7 @@ HTTPS 是 HTTP over SSL 的简称,可以通过如下方式开启 SSL。
523523
| ciphers | 加密套件 | 不限 | null | `required` | 在启用 SSL 时,如果不正确设置,服务会启动失败 |
524524
| enable | 是否启用SSL | {true, false} | false | optional | 建议在配置项明确指定,明确意图 |
525525
| mutual_auth | 是否启用双向认证 | {true, false} | false | optional | - |
526-
| ca_cert_path | CA证书路径 | 不限,xx/path/to/ca.pem | null | optional | 双向认证是开启有效 |
526+
| ca_cert_path | CA证书路径 | 不限,xx/path/to/ca.pem | null | optional | 双向认证时开启有效 |
527527
| protocols | SSL协议版本 | {SSLv2, SSLv3, TLSv1, TLSv1.1, TLSv1.2} | TLSv1.1 + TLSv1.2 | optional | - |
528528

529529
举个例子:

0 commit comments

Comments
 (0)