mirror of
https://github.com/davidallendj/gdpm.git
synced 2025-12-20 03:27:02 -07:00
Implemented parallel downloads through CURL multi interface and added purge command
- Update `README.md` file with examples - Fixed error messages showing no or wrong message - Changed the prompt message when installing, removing, etc. - Changed how http::request works - Added `http::multi` class for parallel downloads - Removed separate `concepts.hpp` file TODO: Fix ZIP not extracting after running the `install` command
This commit is contained in:
parent
766eabd5b2
commit
807aa8e5b2
21 changed files with 1158 additions and 758 deletions
|
|
@ -1,15 +1,71 @@
|
|||
# GDPM HTTP Example
|
||||
# GDPM Rest API Example
|
||||
|
||||
This is an example showing how to use the GDPM HTTP library to download files. The library uses RapidJSON to get results.
|
||||
This is an example showing how to use the REST API designed to query the Godot Asset library in C++. It is built using the `libcurl` library.
|
||||
|
||||
Here is a snippet making a HTTP get and post request.
|
||||
|
||||
Here is a quick snippet to get started:
|
||||
```c++
|
||||
// Get a full list of assets
|
||||
rest_api::context context = rest_api::make_context();
|
||||
rapidjson::Document doc = http::get_asset_list(
|
||||
"https://godotengine.org/asset-library/api",
|
||||
context
|
||||
)
|
||||
// ... parse the rapidjson::Document
|
||||
#include "http.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
using string = std::string;
|
||||
using headers_t = std::unordered_map<string, string>;
|
||||
|
||||
string url = "www.example.com";
|
||||
http::context http;
|
||||
http::request params = {{"user-agent", "firefox"}};
|
||||
http::response r = http::request(url, params);
|
||||
if(r.code == http::OK){ /* ...do something... */ }
|
||||
|
||||
r = http::request(url, params, http::method::POST);
|
||||
if(r.code == http::OK){ /* ...do something.. */ }
|
||||
```
|
||||
|
||||
Here's an example using the `multi` interface for parallel requests and downloads:
|
||||
|
||||
```c++
|
||||
#include "http.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
template <typename T>
|
||||
using ptr = std::unique_ptr<T>;
|
||||
using strings = std::vector<std::string>;
|
||||
using transfers = std::vector<http::transfer>;
|
||||
using responses = std::vector<http::response>;
|
||||
|
||||
http::multi http;
|
||||
http::request params = {{"user-agent", "firefox"}}
|
||||
params.headers.insert(http::header("Accept", "*/*"));
|
||||
params.headers.insert(http::header("Accept-Encoding", "application/gzip"));
|
||||
params.headers.insert(http::header("Content-Encoding", "application/gzip"));
|
||||
params.headers.insert(http::header("Connection", "keep-alive"));
|
||||
|
||||
strings request_urls = {
|
||||
"www.example.com",
|
||||
"www.google.com"
|
||||
}
|
||||
ptr<http::transfers> requests = http::make_requests(request_url, params);
|
||||
ptr<http::responses> responses = http::execute(std::move(requests));
|
||||
for(const auto& r : *responses){
|
||||
if(r.code == http::OK){
|
||||
// ...do something
|
||||
}
|
||||
}
|
||||
|
||||
strings download_urls = {
|
||||
""
|
||||
}
|
||||
strings storage_paths = {
|
||||
"./download1"
|
||||
}
|
||||
ptr<http::transfers> downloads = http::make_downloads(download_url, storage_paths, params);
|
||||
ptr<http::responses> responses = http::execute(std::move(downloads));
|
||||
for(const auto& r : *responses){
|
||||
if(r.code == http::OK){
|
||||
// ...do something
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
@ -1,26 +1,15 @@
|
|||
# GDPM Rest API Example
|
||||
# GDPM HTTP Example
|
||||
|
||||
This is an example showing how to use the REST API designed to query the Godot Asset library in C++. It is built using the `libcurl` library.
|
||||
This is an example showing how to use the GDPM HTTP library to download files. The library uses RapidJSON to get results.
|
||||
|
||||
Here is a snippet making a HTTP get and post request.
|
||||
|
||||
Here is a quick snippet to get started:
|
||||
```c++
|
||||
using string = std::string;
|
||||
using headers_t = std::unordered_map<string, string>;
|
||||
|
||||
std::string url = "www.example.com";
|
||||
http::response r_get = http::request_get(url)
|
||||
if(r_get.response_code == http::response_code::OK){
|
||||
// ...do something...
|
||||
}
|
||||
|
||||
http::request_params params;
|
||||
params.headers = {
|
||||
{"user-agent", "firefox"},
|
||||
{"content-type", "application/json"}
|
||||
}
|
||||
http::response r_post = http::request_post(url, params);
|
||||
if(r_post.response_code == http::response_code::OK){
|
||||
// ...do something...
|
||||
}
|
||||
// Get a full list of assets
|
||||
rest_api::context context = rest_api::make_context();
|
||||
rapidjson::Document doc = http::get_asset_list(
|
||||
"https://godotengine.org/asset-library/api",
|
||||
context
|
||||
)
|
||||
// ... parse the rapidjson::Document
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue