Skip to content

Commit

Permalink
update coro_http doc (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos authored Jan 16, 2024
1 parent 55a6372 commit 44ac4bf
Show file tree
Hide file tree
Showing 9 changed files with 343 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/struct_pb/conformance/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/tests/struct_pb)
find_package(Protobuf QUIET)
if (NOT Protobuf_FOUND)
message(INFO "to build struct_pb conformance test, you must install libprotoc first!!!")
message(INFO "to build struct_pb conformance test, you must install libprotoc first")
return()
endif ()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
Expand Down
2 changes: 1 addition & 1 deletion src/struct_pb/protoc-plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (Protobuf_FOUND)
RUNTIME DESTINATION bin
)
else ()
message(INFO "struct_pb is skipped. To build struct_pb protoc plugin, you must install libprotoc first!!!\n"
message(INFO "struct_pb is skipped. To build struct_pb protoc plugin, you must install libprotoc first\n"

"see https://alibaba.github.io/yalantinglibs/en/struct_pb/struct_pb_generating_your_struct.html"
)
Expand Down
4 changes: 2 additions & 2 deletions website/.vitepress/config/zh_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export const easylog_Links = [
{ text: 'easylog简介', link: '/zh/easylog/easylog_introduction' },
];

export const coro_http_client_Links = [
{ text: 'coro_http_client简介', link: '/zh/coro_http_client/coro_http_client_introduction' },
export const coro_http_Links = [
{ text: 'coro_http 简介', link: '/zh/coro_http /coro_http_introduction' },
];

export const struct_xxx_Links = [
Expand Down
2 changes: 1 addition & 1 deletion website/.vitepress/config/zh_locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const zh_themeConfig = <DefaultTheme.Config>
{ text: 'struct_pb', items: data.struct_pb_Links, },
{ text: 'coro_rpc', items: data.coro_rpc_Links },
{ text: 'easylog', items: data.easylog_Links },
{ text: 'coro_http_client', items: data.coro_http_client_Links },
{ text: 'coro_http', items: data.coro_http_Links },
{ text: 'struct_xxx', items: data.struct_xxx_Links },
]
};
Expand Down
29 changes: 28 additions & 1 deletion website/docs/en/guide/what_is_yalantinglibs.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,40 @@ void basic_usage() {

## coro_http

coro_http is a C++20 coroutine http(https) client, include: get/post, websocket, multipart file upload, chunked and ranges download etc.
coro_http is a C++20 coroutine http(https) library, include server and client, functions: get/post, websocket, multipart file upload, chunked and ranges download etc. [more examples](https://github.com/alibaba/yalantinglibs/blob/main/src/coro_http/examples/example.cpp)

### get/post
```c++
#include "ylt/coro_http/coro_http_server.hpp"
#include "ylt/coro_http/coro_http_client.hpp"
using namespace coro_http;

async_simple::coro::Lazy<void> basic_usage() {
coro_http_server server(1, 9001);
server.set_http_handler<GET>(
"/get", [](coro_http_request &req, coro_http_response &resp) {
resp.set_status_and_content(status_type::ok, "ok");
});

server.set_http_handler<GET>(
"/coro",
[](coro_http_request &req,
coro_http_response &resp) -> async_simple::coro::Lazy<void> {
resp.set_status_and_content(status_type::ok, "ok");
co_return;
});
server.aync_start(); // aync_start() don't block, sync_start() will block.
std::this_thread::sleep_for(300ms); // wait for server start

coro_http_client client{};
auto result = co_await client.async_get("http://127.0.0.1:9001/get");
assert(result.status == 200);
assert(result.resp_body == "ok");
for (auto [key, val] : result.resp_headers) {
std::cout << key << ": " << val << "\n";
}
}

async_simple::coro::Lazy<void> get_post(coro_http_client &client) {
std::string uri = "http://www.example.com";
auto result = co_await client.async_get(uri);
Expand Down
4 changes: 2 additions & 2 deletions website/docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ features:
details: Very easy-to-use, coroutine-based, high performance rpc framework with C++20, more than 2000w qps in echo scene.
- title: struct_json\struct_xml\struct_yaml
details: C++17 reflection-based json lib, very easy to do struct to json\xml\yaml and json\xml\yaml to struct.
- title: coro_http_client
details: C++20 coroutine http(https) client, include get/post, websocket, multipart file upload, chunked and ranges download etc.
- title: coro_http
details: C++20 coroutine http(https) server and client, include get/post, websocket, multipart file upload, chunked and ranges download etc.
- title: easylog
details: C++17 high performance and easy to use logging lib, support cout、sprintf and fmt::format/std::format stream.
---
Loading

0 comments on commit 44ac4bf

Please sign in to comment.