source /opt/phytec-yogurt/BSP-Yocto-i.MX6-PD18.1.1/environment-setup-cortexa9hf-neon-phytec-linux-gnueabi
should have done something like that, but apparently it didn't.
Hello @mmn:matrix.org ,
The macros are used throughout the examples, but AFAIK it isn't explained anywhere what they do.
You can find docs on ORM, DTO, and other oatpp components here on the website:
If you feel that those docs aren't enough - please file an issue on Github - in oatpp website repo - https://github.com/oatpp/website
//My client class
class VoucherClient : public oatpp::web::client::ApiClient
{
#include OATPP_CODEGEN_BEGIN(ApiClient)
API_CLIENT_INIT(VoucherClient)
API_CALL_ASYNC("POST", "/", getRoot)
API_CALL("POST", "/connect", connect, BODY_STRING(String, ip))
#include OATPP_CODEGEN_END(ApiClient)
};
//My API call function :
void funcCall(shared_ptr<VoucherClient> client)
{
cout << "[Connect] Calling the server..." << endl;
auto data = client->connect("127.0.0.1")->readBodyToString(); //Crash dans le thread
OATPP_LOGD("CLIENT", "[connect] data='%s'", data->c_str());
}
//My run function :
void run()
{
cout << "Creating objectmapper" << endl;
auto objectMapper = oatpp::parser::json::mapping::ObjectMapper::createShared();
cout << "Creating requestexecutor" << endl;
auto requestExecutor = createOatppExecutor();
cout << "Creating client" << endl;
auto client = VoucherClient::createShared(requestExecutor, objectMapper);
std::thread th(client);
}
//My main function :
int main()
{
oatpp::base::Environment::init();
printHelp();
run();
oatpp::base::Environment::destroy();
cout << "Press any key to close the program" << endl;
_getch();
return 0;
}
Hi,
I am evaluating simple/efficient and dependency-lite framework to create REST C++ backend for WEB app frontend which will be in typescript and PostgreSql as database.
So short question is: am I in the right place? :)
Also, I would like to have some Swagger that can "use" (read: serialize/load) to/from JSON and C++ model classes. This is not necessary, but nice bonus.
I tried PHP, but I really don't feel comfortable with it. Python is bit slow for my taste, so maybe its time to get back home to the one I love - C++.
Thanks in advance
Has there been any consideration for adding support for the http/2 spec and eventually http/3?
@JeremyGuinn , http2/3 isn't a priority for oatpp at the moment.
The main reason is that http2/3 are mainly designed for better multimedia content delivery - serving APIs is arguably more effective with HTTP 1.1 (depends on the application)
However, I think it should be possible to integrate oatpp with ex.: h2o server
The browser and server are upgraded to websocket protocol and the connection is established successfully. Does the server support sending data actively?
What solution should be set if you want the server to actively send data information after the connection is established?
Hey @shijiantouzouyiqie , sure - when a client is connected to the server, you'r getting the WebSocket
object representing the client -
https://github.com/oatpp/example-websocket/blob/master/server/src/websocket/WSListener.cpp#L43.
Then you can write data to that socket, using sendOneFrameText
or sendOneFrameBinary
methods.
Hi,
I am evaluating simple/efficient and dependency-lite framework to create REST C++ backend for WEB app frontend which will be in typescript and PostgreSql as database.
So short question is: am I in the right place? :)
Also, I would like to have some Swagger that can "use" (read: serialize/load) to/from JSON and C++ model classes. This is not necessary, but nice bonus.
Hello @nikoladsp , yes, you are in the right place :)
Please check-out this example project - https://github.com/oatpp/example-postgresql
It's basically a web-service which talks to postgres, and has swagger-ui
I got a basic question. Is an Oat++ server a standalone executable or does it require a web server to run in production, with the custom logic running as CGI or .dll or something like that? I have a custom application in mind and I need it to be easy to run and install.
Hello @peterritter , yes, Oat++ server is a standalone executable.
void WSInstanceListener::onAfterCreate(const oatpp::websocket::WebSocket& socket, const std::shared_ptr<const ParameterMap>& params) {
socket.sendOneFrameText("Hello");
SOCKETS ++;
OATPP_LOGD(TAG, "New Incoming Connection. Connection count=%d", SOCKETS.load());
/* In this particular case we create one WSListener per each connection */
/* Which may be redundant in many cases */
socket.setListener(std::make_shared<WSListener>());
}
I |2021-12-01 14:35:37 1638340537126253| MyApp:Server running on port 8000
D |2021-12-01 14:35:39 1638340539806813| Server_WSInstanceListener:New Incoming Connection. Connection count=1
D |2021-12-01 14:35:39 1638340539876373| [oatpp::web::protocol::websocket::WebSocket::listen()]:Unhandled error occurred. Message='[oatpp::web::protocol::websocket::WebSocket::readFrameHeader()]: Error reading frame header'
D |2021-12-01 14:35:39 1638340539876411| Server_WSInstanceListener:Connection closed. Connection count=0
Hey @shijiantouzouyiqie ,
Looks like at this point the WS connection appears to be not fully established (and it's a bug).
So you don't want to write to the client socket directly from this method. Instead you can use a separate thread:
void WSInstanceListener::onAfterCreate(const oatpp::websocket::WebSocket& socket, const std::shared_ptr<const ParameterMap>& params) {
SOCKETS ++;
OATPP_LOGD(TAG, "New Incoming Connection. Connection count=%d", SOCKETS.load());
/* In this particular case we create one WSListener per each connection */
/* Which may be redundant in many cases */
socket.setListener(std::make_shared<WSListener>());
std::thread t([&socket]{
socket.sendOneFrameText("Hello");
});
t.detach();
}
Please file an issue on Github. WS Connection should be fully established by the time WSInstanceListener::onAfterCreate
method is called.
ENDPOINT("GET", "ws", ws, REQUEST(std::shared_ptr<IncomingRequest>, request)) {
return oatpp::websocket::Handshaker::serversideHandshake(request->getHeaders(), websocketConnectionHandler);
};
I tried to make MySecurApiCall Automatic Retries by following the doc:
OATPP_CREATE_COMPONENT(std::shared_ptr<MySecureApiCall>, mySecureApiClient)([] {
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, connectionProvider, "clientConnectionProvider");
OATPP_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, objectMapper);
// create connection pool
auto connectionPool = oatpp::network::ClientConnectionPool::createShared(
connectionProvider, // connection provider
10, //max connections
std::chrono::seconds(5) // max lifetime of idle connection
);
// create retry policy
auto retryPolicy = oatpp::web::client::SimpleRetryPolicy(2 /* max retries */, std::chrono::seconds(1) /* retry interval */);
//auto requestExecutor = oatpp::web::client::HttpRequestExecutor::createShared(connectionProvider);
auto requestExecutor = oatpp::web::client::HttpRequestExecutor::createShared(connectionPool, retryPolicy /* retry policy */);
return MySecureApiCall::createShared(requestExecutor, objectMapper);
}());
I have modified some lines of the example, but still have "no matching function for call compile" error for "auto requestExecutor = oatpp.... " line. Please tell me what was wrong. Thank you for your help in advance.
retryPolicy
should be shared_ptr
- https://github.com/oatpp/oatpp/blob/master/src/oatpp/web/client/HttpRequestExecutor.hpp#L115
Hello @mmn:matrix.org ,
What is the canonical way to check whether a DTO field was "filled" during a deserialisation (using oatpp::parser::json::mapping::ObjectMapper)?
At the moment it's the following:
ENDPOINT("POST", "users", createUser,
BODY_DTO(Object<UserDto>, userDto))
{
OATPP_ASSERT_HTTP(userDto->id, Status::CODE_400, "id field is required")
OATPP_ASSERT_HTTP(userDto->role, Status::CODE_400, "role field is required")
...
}
Or, you can move those checks ex.: to UserDto:
class UserDto : oatpp::DTO {
...
validate() {
OATPP_ASSERT_HTTP(userDto->id, Status::CODE_400, "id field is required")
OATPP_ASSERT_HTTP(userDto->role, Status::CODE_400, "role field is required")
}
};
...
ENDPOINT("POST", "users", createUser,
BODY_DTO(Object<UserDto>, userDto))
{
userDto->validate();
...
}