{"id":16679670,"url":"https://github.com/mrk21/cpp-webmock","last_synced_at":"2025-10-13T07:15:25.002Z","repository":{"id":22626138,"uuid":"25968696","full_name":"mrk21/cpp-webmock","owner":"mrk21","description":"The cpp-webmock is HTTP mocking library that was created by referencing to WebMock of Ruby.","archived":false,"fork":false,"pushed_at":"2015-01-21T09:09:22.000Z","size":648,"stargazers_count":1,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T02:44:35.505Z","etag":null,"topics":["cpp","cpp14"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrk21.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-30T11:55:24.000Z","updated_at":"2021-05-01T15:05:47.000Z","dependencies_parsed_at":"2022-08-20T21:50:44.528Z","dependency_job_id":null,"html_url":"https://github.com/mrk21/cpp-webmock","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/mrk21/cpp-webmock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrk21%2Fcpp-webmock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrk21%2Fcpp-webmock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrk21%2Fcpp-webmock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrk21%2Fcpp-webmock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrk21","download_url":"https://codeload.github.com/mrk21/cpp-webmock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrk21%2Fcpp-webmock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279014113,"owners_count":26085461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","cpp14"],"created_at":"2024-10-12T13:36:46.294Z","updated_at":"2025-10-13T07:15:24.986Z","avatar_url":"https://github.com/mrk21.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"cpp-webmock\n=====================\n\nThe cpp-webmock is HTTP mocking library that was created by referencing to [WebMock](https://github.com/bblimke/webmock \"bblimke/webmock\") of Ruby.\n\n## Introduction\n\nIn order to introduce cpp-webmock, we need basing on steps listed below:\n\nFirst, if we had the following code that is using the [cpp-netlib](http://cpp-netlib.org/ \"The C++ Network Library Project\") that is HTTP library:\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003cboost/network/protocol/http/client.hpp\u003e\n\nint main() {\n    namespace network = boost::network;\n    namespace http = network::http;\n    using client_type = http::client;\n    \n    client_type::request request(\"http://www.boost.org/\");\n    request \u003c\u003c network::header(\"Connection\",\"Close\");\n    client_type client;\n    client_type::response response = client.get(request);\n    \n    std::cout \u003c\u003c \"status: \" \u003c\u003c http::status(response) \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"body: \" \u003c\u003c http::body(response) \u003c\u003c std::endl;\n    \n    return 0;\n}\n```\n\nWhen this code built and executed, it outputs as shown below:\n\n```bash\nstatus: 200\nbody: \u003c!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n   \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"\u003e\n\n\u003chtml xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\"\u003e\n\u003chead\u003e\n \u003cmeta name=\"generator\" content=\n \"HTML Tidy for Windows (vers 1st November 2003), see www.w3.org\" /\u003e\n \n \u003ctitle\u003eBoost C++ Libraries\u003c/title\u003e\n...\n```\n\nNext, we will continue to introduce cpp-webmock to this code based on steps listed below:\n\n1. Include `webmock/api.hpp` and `webmock/adapter/cpp_netlib.hpp`\n1. Change the client type from `boost::network::http::client` to `webmock::adapter::cpp_netlib::client`\n1. Set the behavior when the specifying URL accessed by `a_stub`\n1. If you want to verify whether the client accessing the specified URL, you will use `a_request`\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003cboost/network/protocol/http/client.hpp\u003e\n#include \u003cwebmock/api.hpp\u003e                // 1.\n#include \u003cwebmock/adapter/cpp_netlib.hpp\u003e // 1.\n\nint main() {\n    namespace network = boost::network;\n    namespace http = network::http;\n    using client_type = webmock::adapter::cpp_netlib::client; // 2.\n    \n    using namespace webmock::api::directive;                            // 3.\n    a_stub(\"http://www.boost.org/\").returns(a_response().body(\"test\")); // 3.\n    \n    client_type::request request(\"http://www.boost.org/\");\n    request \u003c\u003c network::header(\"Connection\",\"Close\");\n    client_type client;\n    client_type::response response = client.get(request);\n    \n    std::cout \u003c\u003c \"status: \" \u003c\u003c http::status(response) \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"body: \" \u003c\u003c http::body(response) \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"access count: \"                                  // 4.\n        \u003c\u003c a_request(\"http://www.boost.org/\")                      // 4.\n            .conditions(with_header(\"Connection\",\"Close\")).count() // 4.\n        \u003c\u003c std::endl;                                              // 4.\n    \n    return 0;\n}\n```\n\nFinally, let's see what this code can execute:\n\n```\nstatus: 200\nbody: test\naccess count: 1\n```\n\nWe did it! The response that is set by `a_stub` has been returned!\n\n## Installation\n\nThe cpp-webmock is header-only library, so you do not need to build. In order to use this library, you should prepare that listed below:\n\n* Clang 3.5 (with -std=c++14)\n* Boost 1.56\n* HTTP library (In the current, it corresponds cpp-netlib only)\n\nIf you use CMake to build, you might want to as following:\n\nFirst, you add the `external` directory and `CMakeLists.txt` to your project:\n\n```\nproject_root\n├── CMakeLists.txt\n├── src.cpp\n└── external            # Adding\n     └── CMakeLists.txt # Adding\n```\n\nSecond, you write the following content to added `external/CMakeLists.txt`:\n\n```cmake\ncmake_minimum_required(VERSION 3.0.2)\n\ninclude(ExternalProject)\n\nExternalProject_Add(webmock\n  GIT_REPOSITORY https://github.com/mrk21/cpp-webmock.git\n  GIT_TAG v0.3.0\n  PREFIX webmock\n  CMAKE_ARGS\n    -DCMAKE_INSTALL_PREFIX=\u003cINSTALL_DIR\u003e\n    -DBUILD_LIBRARY=ON\n)\n```\n\nFinally, you append the following content to your project's `CMakeLists.txt`:\n\n```cmake\ncmake_minimum_required(VERSION 3.0.2)\n\nmessage(\"Building externals...\")\ntry_compile(external_status\n  ${PROJECT_BINARY_DIR}/external\n  ${PROJECT_SOURCE_DIR}/external\n  external\n  OUTPUT_VARIABLE external_result\n)\nif(NOT external_status)\n  message(\"${external_result}\")\n  return()\nendif()\nmessage(\"Built externals\")\ninclude(${PROJECT_BINARY_DIR}/external/webmock/lib/webmock.cmake)\n\nadd_compile_options(-std=gnu++14)\nadd_executable(bin src.cpp)\ntarget_link_libraries(bin webmock::webmock)\n```\n\n## Reference\n\n* [webmock::request](#webmockrequest)\n* [webmock::response](#webmockresponse)\n* [webmock::api::a\\_stub](#webmockapia_stub)\n    * [constructor](#constructor)\n    * [returns()](#returns)\n    * [conditions()](#conditions)\n    * [operator \u0026lt;\u0026lt;](#operator-)\n    * [count()](#count)\n    * [operator std::size\\_t](#operator-stdsize_t)\n* [webmock::api::a\\_request](#webmockapia_request)\n* [webmock::api::a\\_response](#webmockapia_response)\n* [webmock::api::an\\_error](#webmockapian_error)\n* [webmock::api::with\\_method](#webmockapiwith_method)\n* [webmock::api::with\\_url](#webmockapiwith_url)\n* [webmock::api::with\\_body](#webmockapiwith_body)\n* [webmock::api::with\\_header](#webmockapiwith_header)\n* [webmock::api::with](#webmockapiwith)\n* [webmock::api::directive](#webmockapidirective)\n* [webmock::api::reset()](#webmockapireset)\n* [webmock::api::allow\\_connecting\\_to\\_net()](#webmockapiallow_connecting_to_net)\n* [webmock::api::disallow\\_connecting\\_to\\_net()](#webmockapidisallow_connecting_to_net)\n* [webmock::api::stub\\_not\\_found\\_callback()](#webmockapistub_not_found_callback)\n* [webmock::adapter::cpp\\_netlib::basic\\_client](#webmockadaptercpp_netlibbasic_client)\n* [webmock::adapter::cpp\\_netlib::select\\_by\\_type](#webmockadaptercpp_netlibselect_by_type)\n* [webmock::adapter::cpp\\_netlib::select\\_by\\_param](#webmockadaptercpp_netlibselect_by_param)\n\n### webmock::request\n\nThe `webmock::request` is a structure to store a content of the request from the client.\n\n```cpp\nstruct request {\n    core::http::method method;\n    core::http::url url;\n    core::http::headers headers;\n    core::http::body body;\n};\n```\n\nThis structure is defined the stream operator and comparative operator.\n\n### webmock::response\n\nThe `webmock::response` is a structure to store a response returning to the client.\n\n```cpp\nstruct response {\n    core::http::status status;\n    core::http::body body;\n    core::http::headers headers;\n};\n```\n\nThis structure is defined the stream operator and comparative operator.\n\n### webmock::api::a\\_stub\n\nThe `a_stub` class sets a behavior of when specifying URL was accessed. This class has methods and operators listed below:\n\n#### constructor\n\n```cpp\na_stub::a_stub();\na_stub::a_stub(with_url const \u0026 url);\na_stub::a_stub(with_method const \u0026 method, with_url const \u0026 url);\n```\n\nThe `method` argument specifies a HTTP method, and the `url` argument specifies an URL.\n\nA stub set by `a_stub` will be inserted to a head of the stub list. When the client accessed, a stub matching the request will be found by linear search since a head in the stub list. Therefore, if it is found multiple, selects a stub added after.\n\n```cpp\na_stub(\"http://www.boost.org/\").returns(a_response().body(\"response 1\"));\na_stub(\"http://www.boost.org/\").returns(a_response().body(\"response 2\"));\n\nclient_type::request request(\"http://www.boost.org/\");\nclient_type client;\nclient_type::response response = client.get(request);\n\nstd::cout \u003c\u003c http::body(response) \u003c\u003c std::endl; // response 2\n```\n\n#### returns()\n\n```cpp\na_stub \u0026 a_stub::returns(core::response_sequence const \u0026 response_sequence[, ...]);\n```\n\nThe `returns()` method sets the behavior returning a response. The behavior can be set multiple, and it returns the response on specified order when the client accessed every time. If the number of access was greater than the number of the specified behaviors, it keeps to return a response of the behavior last specified.\n\n```cpp\na_stub(url)\n    .returns(a_response().body(\"response 1\"))\n    .returns(a_response().body(\"response 2\"))\n    .returns(a_response().body(\"response 3\"));\n```\n\nFor example, if it specified as above, when the client accessed the `url`, it will return responses shown below:\n\n```\nresponse 1\nresponse 2\nresponse 3\nresponse 3\n...\n```\n\nIn addition, it can specify multiple as shown below:\n\n```cpp\na_stub(url).returns(\n    a_response().body(\"response 1\"),\n    a_response().body(\"response 2\"),\n    a_response().body(\"response 3\")\n);\n```\n\n#### conditions()\n\n```cpp\na_stub \u0026 a_stub::conditions(core::condition_list::condition_type condition[, ...]);\n```\n\nThe `condition()` method, such as whether to exist HTTP header and a condition of a request body, adds conditions of a request. This conditions are such as `with_method` and `with_body`. For example, if HTTP method was `GET` and the request body was `test`, it returns `400`:\n\n```cpp\na_stub()\n    .conditions(with_method(\"GET\"))\n    .conditions(with_body(\"test\"))\n    .returns(a_response().status(400));\n```\n\nThe `condition()` method can also specify as multiple as `returns()` method:\n\n```cpp\na_stub().conditions(\n    with_method(\"GET\"),\n    with_body(\"test\")\n).returns(a_response().status(400));\n```\n\n#### operator \u0026lt;\u0026lt;\n\n```cpp\na_stub \u0026 operator \u003c\u003c(a_stub \u0026 lop, core::response_sequence const \u0026 rop);\na_stub \u0026 operator \u003c\u003c(a_stub \u0026 lop, core::condition_list::condition_type rop);\n```\n\nIn the above, I said to use the `returns()` method if you want to specify responses, and said to use the `conditions()` method if want to add conditions, but you can also realize these functions by using the `\u003c\u003c` operator.\n\n```cpp\na_stub()\n    \u003c\u003c with_method(\"GET\")\n    \u003c\u003c with_body(\"test\")\n    \u003c\u003c a_response().status(400);\n```\n\n#### count()\n\n```cpp\nstd::size_t a_stub::count() const;\n```\n\nThis method returns the number of responses returned–the number of requested.\n\n```cpp\nauto \u0026\u0026 stub = a_stub(\"http://www.hogebar.com/\").returns(a_response());\n\nclient_type client;\nclient.get(client_type::request{\"http://www.hogebar.com/\"});\nclient.get(client_type::request{\"http://www.hogebar.com/\"});\n\nstd::cout \u003c\u003c stub.count() \u003c\u003c std::endl; // 2\n```\n\n#### operator std::size\\_t\n\n```cpp\nstd::size_t a_stub::operator std::size_t() const;\n```\n\nThis is conversion operator to convert to an integer type. The returned value equals to the value getting from `count()` method:\n\n```cpp\nstd::cout \u003c\u003c std::boolalpha \u003c\u003c (stub \u003c 3) \u003c\u003c std::endl; // true\n```\n\n### webmock::api::a\\_request\n\nThe `a_request` class is for verifying how the client requested, and it is removed from the `a_stub` the function creating responses and the function registering to the stub list. This will use to verify requests to multiple stubs:\n\n```cpp\na_stub(\"http://www.hogebar.com/a\").returns(a_response());\na_stub(\"http://www.hogebar.com/b\").returns(a_response());\n\nclient_type client;\nclient.get(client_type::request{\"http://www.hogebar.com/a\"});\nclient.get(client_type::request{\"http://www.hogebar.com/b\"});\n\nstd::cout \u003c\u003c a_request(std::regex(\"http://www.hogebar.com/.*\")).count() \u003c\u003c std::endl; // 2\n```\n\n### webmock::api::a\\_response\n\n```cpp\nstatic_response a_response(core::response const \u0026 response = {});\ndynamic_response a_response(dynamic_response::generator_type generator);\n```\n\nThe `a_response` function generates a response to specify to the `stub::returns()` method.\n\nThe first form generates a static response not depended to the request. The `response` specifies `webmock::response` that is a content of a response:\n\n```cpp\na_response({200, \"test\", {\n    {\"Content-Type\", \"text/plane\"},\n    {\"Set-Cookie\", \"a=1\"},\n    {\"Set-Cookie\", \"b=2\"}\n}});\n```\n\nThe following methods can also specify the content of the response as above:\n\n```\nstatic_response \u0026 static_response::status(core::http::status const \u0026 status);\nstatic_response \u0026 static_response::body(core::http::body const \u0026 body);\nstatic_response \u0026 static_response::header(\n    core::http::header_name const \u0026 name,\n    core::http::header_value const \u0026 value\n);\n```\n\n```cpp\na_response().status(200).body(\"test\")\n    .header(\"Content-Type\", \"text/plane\")\n    .header(\"Set-Cookie\", \"a=1\")\n    .header(\"Set-Cookie\", \"b=2\");\n```\n\nThe second form generates a response by the request. The `generator` specifies an unary function that receives a request from the client:\n\n```cpp\na_response([](webmock::request const \u0026 request){\n    webmock::response response;\n    response.status = 200;\n    response.body = request.body;\n    return response;\n});\n```\n\nThis form cannot use above methods such as `status()`.\n\nIn addition, any form can return same response a number of times specified by `times()` method or operator `*`:\n\n```cpp\na_stub(url)\n    \u003c\u003c a_response().body(\"response 1\").times(2)\n    \u003c\u003c a_response().body(\"response 2\") * 2\n    \u003c\u003c a_response().body(\"response 3\");\n```\n\n```\nresponse 1\nresponse 1\nresponse 2\nresponse 2\nresponse 3\nresponse 3\n...\n```\n\n### webmock::api::an\\_error\n\n```cpp\ntemplate \u003ctypename T\u003e\nerror_response an_error(T value);\n\ntemplate \u003ctypename Exception, typename... Types\u003e\nerror_response an_error(Types... args);\n```\n\nThis function also specifies to the `a_stub::returns()` method in the same way as `a_response()` function, but it is not returning a response but throwing an exception. This function will use to reproduce such as name resolution failure(The cpp-netlib throws an exception if name resolution failed).\n\nThe first form throws the value `value`, but the second form throws an instance that is generated by a constructor of the exception class `Exception` with arguments `args`.\n\nIn addition, any form can throw multiple exceptions a number of times specified by `times()` method or operator `*` in the same way as `a_response`:\n\n```cpp\na_stub(url)\n    \u003c\u003c an_error(\"Host not found (authoritative)\") * 2\n    \u003c\u003c an_error\u003cstd::logic_error\u003e(\"Host not found (authoritative)\");\n```\n\n### webmock::api::with\\_method\n\n```cpp\nwith_method(core::http::method const \u0026 value);\nwith_method(std::regex const \u0026 regex);\n```\n\nThe `with_method` class instance is for specifying to `a_stub::conditions()` method, and its constructor specifies a request HTTP method.\n\nThe first form determines whether to equal to the specified value `value`, and the second form determines whether to match to the specified regular expression `regex`.\n\n### webmock::api::with\\_url\n\n```cpp\nwith_url(core::http::url const \u0026 value);\nwith_url(std::regex const \u0026 regex);\n```\n\nThe `with_url` class instance is for specifying to `a_stub::conditions()` method, and its constructor specifies a request URL.\n\nThe first form determines whether to equal to the specified value `value`, and the second form determines whether to match to the specified regular expression `regex`.\n\n### webmock::api::with\\_body\n\n```cpp\nwith_body(core::http::body const \u0026 value);\nwith_body(std::regex const \u0026 regex);\n```\n\nThe `with_body` class instance is for specifying to `a_stub::conditions()` method, and its constructor specifies a request body.\n\nThe first form determines whether to equal to the specified value `value`, and the second form determines whether to match to the specified regular expression `regex`.\n\n### webmock::api::with\\_header\n\n```cpp\nwith_header(core::http::header_name const \u0026 name, core::http::header_value const \u0026 value);\nwith_header(core::http::header_name const \u0026 name, std::regex const \u0026 regex);\n```\n\nThe `with_header` class instance is for specifying to `a_stub::conditions()` method, and its constructor specifies a request header.\n\nThe first form determines whether the value that corresponds to specified header name `name` to equal to the value `value`, and the second form determines whether to match to the regular expression `regex`.\n\n### webmock::api::with\n\n```cpp\nwith(core::condition_list::condition_type condition);\n```\n\nThe `with` class instance is for specifying to `a_stub::conditions()` method, and its constructor specifies an unary function that receives the request from the client. This class will use to check the request particularly:\n\n```cpp\na_stub(url).conditions(with([](webmock::request const \u0026 request){\n    using namespace boost::property_tree;\n    ptree json;\n    std::istringstream iss(request.body);\n    json_parser::read_json(iss, json);\n    if (auto \u0026\u0026 id = json.get_optional\u003cint\u003e(\"user.id\")) {\n        if (*id \u003e= 100) return true;\n    }\n    return false;\n}));\n```\n\nIn addition, the `with` class does not use, and instead the unary function can specify also directly.\n\n```cpp\na_stub(url).conditions([](webmock::request const \u0026 request){\n    ...\n});\n```\n\n### webmock::api::directive\n\nThis namespace is inline namespace, and it defines the directives such as `a_stub`, `a_response` and `with_method`. You will become not needing to write the namespace of the directives by using \"using directive\" to this namespace. The symbol names defined in this namespace are not general such as `a_stub`, `a_response` and `with_method`, so it will not conflict even if you used \"using directive\".\n\n```cpp\nusing namespace webmock::api::directive;\n\na_stub(\"http://www.boost.org\")\n    .conditions(with_method(\"GET\"))\n    .returns(a_response().body(\"response1\"));\n\na_request(\"http://www.boost.org\").count();\n```\n\n### webmock::api::reset()\n\n```cpp\nvoid reset();\n```\n\nThis function clears the stub list and access histories. It will use on before and after each test.\n\n### webmock::api::allow\\_connecting\\_to\\_net()\n\n```cpp\nvoid allow_connecting_to_net();\n```\n\nThis function enables `is_connecting_to_net` option. The client usually throws an exception if the stub satisfying the request not found, but if this option enabled, instead the corresponding original client accesses to the network really.\n\n### webmock::api::disallow\\_connecting\\_to\\_net()\n\n```cpp\nvoid disallow_connecting_to_net();\n```\n\nThis function disables `is_connecting_to_net` option.\n\n### webmock::api::stub\\_not\\_found\\_callback()\n\n```cpp\nvoid stub_not_found_callback(\n    application::stub_not_found_callback_type callback = nullptr\n);\n```\n\nThis function specifies the callback `callback` called when a stub satisfying the request not found. This callback is an unary function that receives the request, and it will use to throw an exception for assertion of testing framework. If the callback not specified, the callback will be set the default callback. In addition, if `is_connecting_to_net` option enabled, this callback is never called.\n\n```cpp\nwebmock::api::stub_not_found_callback([](webmock::request const \u0026 request){\n    throw my_exception((std::ostringstream()\n        \u003c\u003c \"A stub satisfying the request not found!\\n\"\n        \u003c\u003c request\n    ).str());\n});\n```\n\n### webmock::adapter::cpp\\_netlib::basic\\_client\n\nThis type is for substituting `boost::network::http::basic_client`. It is template type, and its template parameter specifies the original client type.\n\n```cpp\nusing namespace boost::network;\nusing namespace webmock::adapter;\n\nusing original_client_type = http::basic_client\u003chttp::tags::http_default_8bit_tcp_resolve,1,1\u003e;\nusing client_type = cpp_netlib::basic_client\u003coriginal_client_type\u003e;\n```\n\nIn addition, it defined alias `adapter::cpp_netlib::client` of the client type that specified the `boost::network::http::client` to the template parameter.\n\n### webmock::adapter::cpp\\_netlib::select\\_by\\_type\n\nYou will usually use the macro shown below to switch the original client type and the client type.\n\n```cpp\n#include \u003cboost/network/protocol/http/client.hpp\u003e\n\n#define CPP_NETLIB_CLIENT boost::network::http::client\n#ifndef USE_WEBMOCK\nusing client_type = CPP_NETLIB_CLIENT;\n#else\n#include \u003cwebmock/adapter/cpp_netlib.hpp\u003e\nusing client_type = webmock::adapter::cpp_netlib::basic_client\u003cCPP_NETLIB_CLIENT\u003e;\n#endif\n#undef CPP_NETLIB_CLIENT\n\nint main() {\n    client_type client;\n    ...\n    return 0;\n}\n```\n\nHowever, if you want to switch these for little use, to implement this macro all of the time is bother. At times like this, when you use `select_by_type` meta function, you can switch easy.\n\n```cpp\n#include \u003cboost/network/protocol/http/client.hpp\u003e\n#include \u003cwebmock/adapter/cpp_netlib.hpp\u003e\n\nint main() {\n    namespace http = boost::network::http;\n    namespace webmock_adapter = webmock::adapter::cpp_netlib;\n    using client_type = typename webmock_adapter::select_by_type\u003cUSE_WEBMOCK, http::client\u003e::type;\n    \n    client_type client;\n    ...\n    return 0;\n}\n```\n\nThe first argument specifies a boolean value of whether to switch these. If specified the value that is evaluated to true, selects the adapter client type, and if specified the value that is evaluated to false, selects the original client type. The second argument specifies the original client type that will be base.\n\n### webmock::adapter::cpp\\_netlib::select\\_by\\_param\n\nThis meta function can switch these as in the same way as `select_by_type` meta function, but instead it specifies the template parameters.\n\n```cpp\nusing client_type = typename webmock_adapter::select_by_param\u003cUSE_WEBMOCK,\n    http::tags::http_default_8bit_tcp_resolve, 1, 1\n\u003e::type;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrk21%2Fcpp-webmock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrk21%2Fcpp-webmock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrk21%2Fcpp-webmock/lists"}