mrtazz / restclient-cpp Goto Github PK
View Code? Open in Web Editor NEWC++ client for making HTTP/REST requests
Home Page: http://code.mrtazz.com/restclient-cpp/
License: MIT License
C++ client for making HTTP/REST requests
Home Page: http://code.mrtazz.com/restclient-cpp/
License: MIT License
most REST APIs are JSON based anways. So maybe it would make this a lot nicer to use if it came with an opinionated way of how JSON responses are parsed into objects. At least look into it.
i don't kown that i should put those the your file to my project, just the .h file, or all file?
in the restclient.cpp, #include "restclient-cpp/version.h",but i can't find the version.h,so that i can't put it to my project...can you help me?
just a placeholder issue so it shows up in the issues list
Hello,
So I installed all the files using the configure, make and make install commands.
Now when I use the example I get the following error:
Undefined reference to RestClient::get(std::string const&)
.
Do you have any idea how to fix this?
Thanks your software, I just wonder whether there is a version for Wince, when I tried in my VS2008, I got some error message:(, I am very appreciate if there is a version for WINCE
should comment out curl_global_cleanup() in the put/post/del.
if need gloabal cleanup, may be it is better to add a separated method for it. so as user can call it after all http access finished.
I think the libgtest.so should only be built into the test_program and not the shared object, since it is not used at runtime.
From looking at the Makefile.am, it looks like -lgtest
is included in the test_program in all cases, so I believe a simple fix is to just remove the line
AC_CHECK_LIB([gtest], [main])
from the configure.ac
Does this sound reasonable?
Hi Daniel,
The license of restclient-cpp project looks exactly like MIT license, but it is not explicitly mentioned.
Could you kindly confirm that license of restclient-cpp is MIT license? The clarification would immensely help users who are conscious about licenses and attribution.
Thanking you,
Hello the project is very nice but I don't see support for persistent connections (send multiple requests over the same connection) and also support for a connection pool.
i want to use new RestClient::Connection but with ip like this
new RestClient::Connection("127.0.0.1");
It seems like the proxy connection is timing out:
[ RUN ] ConnectionTest.TestProxy
test/test_connection.cc:224: Failure
Value of: res.code
Actual: 28
Expected: 200
Might be worth looking into running a proxy server in a docker container for that test.
Hello,
I use a multithreaded application where a c++ thread sends some information in a google protocol buffer to a Java thread using RestClient. I want to initialize a timeout of the Rest connection so that to check expiration timeout in case the Java thread do'nt respond. How to do that ? This is the c++ main code.
RestClient::init();
RestClient::Connection* conn = new RestClient::Connection(applicationUrl);
conn->SetTimeout(5);
RestClient::HeaderFields headers;
headers["Accept"] = "application/x-protobuf";
conn->SetHeaders(headers);
std::string url(applicationUrl);
string restRoot((VoiceLayer::getConfigParamValue("REST_ROOT")).c_str());
url.append(restRoot);
string serialized;
stvproto::StartEvent event;
event.set_info(info);
event.SerializeToString(&serialized);
RestClient::Response r=conn->post(url, serialized);
if (r.code==408)
cout <<"Request timeout!!" << endl;
This code results in a response code=-1 ! What's wrong in my code ?? please help me !
Thank you a lot !
Best regards,
Nabila
restclient-cpp emulating the behaviour of curl to unset a proxy address if an empty string is given.
restclient-cpp just returns from the setter function when an empty string is given.
We have now introduced some more configurable options like auth and timeouts, and are looking to add support for headers and cookies. We also have 2 ways now to set configuration options: via passed in parameters and via helper methods. I think this should be converged into one way of doing configuration. So we basically have two options:
I'm not convinced yet which one is nicer to use, so I'm open for feedback on this one.
Hello,
I am getting the following error:
include/restclient-cpp/restclient.h:12:23: fatal error: curl/curl.h: No such file or directory #include <curl/curl.h>
Even though I have libcurl3 installed on ubuntu.
Still, this is what I get during configure.
checking curl/curl.h usability... no checking curl/curl.h presence... no checking for curl/curl.h... no
Could you please provide me some insight, kind of a noob here :$ :)
I'd like to use this little library in a toy project of mine. However, I couldn't find a way to add additional header fields to any of the REST method calls.
Is it planned to support that in the near future? What about the HEAD method? Are you going to support this too?
Hello everybody!
As read in the documentation, it should be possible to create an object (lets say a pointer to an object) of the class connection. For getting that, it is supposed that should be coded the next sencence:
-RestClient::Connection* conn = new RestClient::Connection("http://url.com");
#include
#include "connection.h"
#include "restclient.h"
int main(){
Eclipse
The problem is that there is no problem using the RestClient::get method, but however I cannot build any object of the RestClient::Connection class, so I cannot do the request I want.
The request I want to do needs to have a kind of special header, so I cannot do a normal get request to a single url.
Anybody know how could I fix it? I read it in the documentation and I have tried to check in the test, in order to follow the way it is done there, but is not running neither. I have included the path for the headers and added the library -l restclient-cpp, but I am wondering if the fail could be there, and it is not foud because of there is a different library wich contains it.
I found another memory leak in restclient.cpp.
If the remote server does not respond to the request, line 223 returns from the PUT function before doing the CURL cleanups on lines 229 thru 231. This causes a memory leak.
I tested the following code change and it resolves the leak. This same issue is elsewhere in the file as well.
if (res != CURLE_OK)
{
ret.body = "Failed to query.";
ret.code = -1;
//return ret; //Commented the return
} else { //else added here
long http_code = 0;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
ret.code = static_cast(http_code);
}
Function now has only one return statement.
The code is there (https://github.com/mrtazz/restclient-cpp/blob/master/source/restclient.cpp#L23) but needs documentation in form of a proper comment block for how to use the methods and also a mention in the README so it's easy to find and use.
I am trying to build a simple project with this library and so far no success yet. I think i am doing something.
I built the library with prefix set to --prefix=/usr/local/restclient-cpp.
I copied the sample code from the repo and tried to compile it with the flags below.
g++ -I /usr/local/restclient-cpp/include -std=c++11 main.cpp -o main -v
Below is the output.
`Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.11.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 264.3.102 -v -dwarf-column-info -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0 -I /usr/local/restclient-cpp/include -stdlib=libc++ -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/joefazee/Desktop/curl-test -ferror-limit 19 -fmessage-length 203 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.11.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/s9/w9447kdn4pd5b44ldn7xmxm80000gp/T/main-8a7637.o -x c++ main.cpp
clang -cc1 version 7.3.0 (clang-703.0.31) default target x86_64-apple-darwin15.4.0
ignoring nonexistent directory "/usr/include/c++/v1"
/usr/local/restclient-cpp/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.11.0 -o main /var/folders/s9/w9447kdn4pd5b44ldn7xmxm80000gp/T/main-8a7637.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"RestClient::del(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&)", referenced from:
_main in main-8a7637.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)`
because it's better than the included sinatra web server
Is it possible to use oAuth2 with this library? I would like to build a client for the Google Rest APIs.
Can we have an example in the documentation ? The current documentation says the following :
RestClient::Response RestClient::Connection::put (const std::string & url, const std::string & data )
HTTP PUT method.
Parameters: url to query, data HTTP PUT body
Returns response struct
Add a method to set a custom user agent. This could prepend a custom agent onto the existing restclient-cpp user agent, eg User-Agent: foobar/1.2.3 restclient-cpp/2.0.0
.
This is useful when building a custom reporter on top of a REST client API.
the CI build should block if valgrind finds leaks. The invocation in the Makefile for make valgrind
needs to be changed to valgrind --leak-check=full --error-exitcode=1 ./test-program
. However right now this results in some reported leaks so I will fix those first before adding it blocking to the CI build.
Hia, thanks for your work.
I Suggest two additions to go around ssl errors.
Maybe switchable via parameter or however you like:
Greetings & Thanks
Philipp
I found no call to curl_global_init
in RestClient class. As said in curl documentation: "This function must be called at least once within a program", is it a bug?
Update: Sorry, I found that "If you did not already call curl_global_init
, curl_easy_init
does it automatically."
right now it mostly checks the HTTP return code, to make sure everything went fine. In order to check for some more sophisticated things, we need JSON support. So the steps would be:
Would you merge a change that adds CMake support? I'm having a pretty evil time using this project in my CMake-based project.
I built this on a raspberrypi, but I haven't found a .deb file in the packagecloud repository. Is it possible to upload an ARM .deb too?
Using Valgrind, I found a small memory leak.
You need to add the following code to the post and put methods near the end of the method code.
curl_slist_free_all(header);
Using restclient for a rest api that requires a json query string.
constructing the query string with Jasonvalue.
The ruby server receiving the string cannot process the json as it seems to have "escaped quotes" e.g. {"key":"value"} etc which means it doesn't seem to process it.
when i print out the json to stdout there are no escapes showing.
I often forget refresh dynamic lib cache, which always makes me feel confused.
So I think add ldconfig
directly is good for everyone:)
Thanks!
Hi,
Can this be used on Android and iOS apps? Any info on how to build using latest Android NDK and Android studio will be really helpful.
Thanks,
Command
$ make
Environment
OSX Yosemite 10.10.2
GNU Make 3.81
gxx version 6.1.0
Error
Undefined symbols for architecture x86_64:
"RestClient::post(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)"
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Attempting to compile the library on cygwin yields the libtool error:
libtool: warning: undefined symbols not allowed in x86_64-unknown-cygwin shared
libraries; building static only
Indeed, attempting to compile a program with the library yields a slew of reference not found errors in the vein of:
undefined reference to `RestClient::post(std::string const&, std::string const&,
std::string const&)'
relocation truncated to fit: R_X86_64_PC32 against undefined symbol `RestClient::post(
std::string const&, std::string const&, std::string const&)'
collect2: error: ld returned 1 exit status
#include <libcurl\curl.h>
#include <string>
#include <map>
#include <cstdlib>
#include "meta.h"
#include <algorithm>
#include <iostream>
#include <functional>
#include <locale>
#include <numeric>
#include <cctype>
The following was observed in AOSP. Calling curl_global_cleanup at the end of every request is harmful, because it cleans up OpenSSL's internal algorithm directory by EVP_Cleanup, effectively undoing OpenSSL_add_all_algorithms(). If OpenSSL is used between requests, for instance certificate vaildation fails with a signature error 7 since the library cannot lookup for algorithms. I would suggest removing the curl_global_cleanup call as AFAIK it's not really needed.
When using just the simple API provided by restclient.h, The curl include seems to be unnecessary:
#include <curl/curl.h> // needed?
If the consumer of restclient-cpp wants to use only restclient.h, it would be best to avoid having to configure the curl include path. (Even pointing to libcurl.lib can be avoided if restclient-cpp is built using the "Link Library Dependencies" option in VS.)
Great library, BTW!
Having proxy variables such as http_proxy, https_proxy, ftp_proxy
make the tests fail. Should these environment variables be considered while running the tests?
Also unsetting those variables make the RestClientPutTest.TestRestClientPUTHeaders
test fail and all others pass, since the request is made to heroku
server.
How to use https?
Hi!
I'm using a slightly modified version of the advanced example from the README and having issues getting off the ground. Specifically, the response object returned from conn -> post(...)
comes back instantly with code 500 and an empty body. The server it's supposed to be talking to receives no requests.
The code I'm using looks like this
Proxy::Proxy(Proxy::Settings settings)
{
// parse settings
RestClient::init();
}
Proxy::~Proxy()
{
RestClient::disable();
}
// requests are handled by a thread pool
Proxy::Request(...)
{
// translate end-user request for back-end server
std::string workerAddress; // address to back-end server, no trailing slash
std::string payload; // json string with escaped quotes
std::unique_ptr<RestClient::Connection> conn(new RestClient::Connection(workerAddress));
conn->SetTimeout(1);
RestClient::HeaderFields headers;
headers["Content-Type"] = "application/json";
conn->SetHeaders(headers);
RestClient::Response r = conn->post("/", payload);
// translate r back to what the end-user wants
}
Thanks for any help in the right direction!
In README.md
the Content-Cype
is supplied in the example for making a POST:
RestClient::Response r = conn->post("/post", "text/json", "{\"foo\": \"bla\"}")
However, include/restclient-cpp/connection.h
has the POST api as:
RestClient::Response post(const std::string& uri,
const std::string& data);
In the current API, this should probably be two calls, one to conn->AppendHeader("Content-Type", "text/json")
and then conn->post(uri,data)
This is also true for the PUT example.
Hello, what type of LICENSE is associated with this software? The license file gives a description of what is expected; however, it does not explicitly call out a license. I am looking to describe the license terms and am wondering if it is one of the well known license types (MIT, BOOST, Public Domain/Unlicense, etc...). Thank you
http2 is coming and libcurl has support for it (http://http2-explained.haxx.se/content/en/part11.html). Let's figure out how to start supporting it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.