Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
167 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,76 @@ | ||
li::http_client | ||
|
||
/* | ||
http_client | ||
=============================== | ||
`li::http_client` is an easy to use http client built around | ||
the libcurl library. | ||
## Header | ||
```c++ | ||
#include <lithium_http_client.hh> | ||
``` | ||
## Introduction | ||
`li::http_client` is an easy to use blocking http client wrapping the libcurl library. | ||
Lithium use it internally to test http servers. Thanks to Lithium's metamap and named parameters, it | ||
simplifies a lot the writing of HTTP requests. | ||
# Tutorial | ||
### Dependencies | ||
- libcurl | ||
```c++ | ||
using namespace li; | ||
// Simple GET request: | ||
auto res = http_get("http://www.google.com"); | ||
// returns an object with a status and a body member. | ||
std::cout << res.status << std::endl; | ||
std::cout << res.body << std::endl; | ||
## Tutorial | ||
// http_post, http_put, http_delete are also avalable. | ||
*/ | ||
|
||
// GET and POST Parameters. | ||
auto res = http_post("http://my_api.com/update_test", | ||
s::get_parameters = mmm(s::id = 42), | ||
s::post_parameters = mmm(s::name = "John", s::age = 42)); | ||
#include <lithium_http_client.hh> | ||
|
||
// Access to headers. | ||
auto res = http_get("http://my_api.com/hello", s::fetch_headers); | ||
// returns an object with a status, body AND headers member. | ||
for (auto pair : res.headers) { | ||
std::cout << pair.first << ":::" << pair.second << std::endl; | ||
} | ||
``` | ||
using namespace li; | ||
|
||
int main() | ||
{ | ||
|
||
# What is the s:: namespace ? | ||
// Simple GET request: | ||
auto res = http_get("http://www.google.com"); | ||
// returns an object with a status and a body member. | ||
std::cout << res.status << std::endl; | ||
std::cout << res.body << std::endl; | ||
|
||
Everything explained here: https://github.com/matt-42/lithium/tree/master/libraries/symbol#lisymbol | ||
// http_post, http_put, http_delete are also avalable. | ||
|
||
# Installation / Supported compilers | ||
// GET and POST Parameters. | ||
auto res = http_post("http://my_api.com/update_test", | ||
s::get_parameters = mmm(s::id = 42), | ||
s::post_parameters = mmm(s::name = "John", s::age = 42)); | ||
|
||
Everything explained here: https://github.com/matt-42/lithium#installation | ||
// Access to headers. | ||
auto res = http_get("http://my_api.com/hello", s::fetch_headers); | ||
// returns an object with a status, body AND headers member. | ||
for (auto pair : res.headers) { | ||
std::cout << pair.first << ":::" << pair.second << std::endl; | ||
} | ||
|
||
} | ||
/* | ||
## Reference | ||
```c++ | ||
auto result = http_[get/post/put/delete](std::string url, options...) | ||
``` | ||
Send a get/post/put/delete HTTP request at the provided url. The return value contains the following fields: | ||
- `int result.status`: The status of the HTTP response | ||
- `string result.body`: The body of the HTTP response | ||
- `map<string, string> result.headers`: Only if option `s::fetch_headers` is provided. The headers of the HTTP response. | ||
# Authors | ||
Matthieu Garrigues https://github.com/matt-42 | ||
Available options: | ||
- `s::get_parameters` : a metamap of the GET parameters. | ||
- `s::post_parameters` : a metamap of the POST parameters. | ||
- `s::fetch_headers` : add the headers field to the return value. | ||
- `s::disable_check_certificate`: disable SSL certificate check. | ||
- `s::json_encoded` : JSON encode the POST parameters (default: url encode) | ||
*/ | ||
|
||
# Support the project | ||
|
||
If you find this project helpful, please consider donating: | ||
https://www.paypal.me/matthieugarrigues | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters