memgraph/speedy/test.cpp
Dominik Tomičević 71dad5a6af fixed speedy
2015-10-07 02:24:21 +02:00

68 lines
1.7 KiB
C++

#include <iostream>
#include "speedy.hpp"
const char *test_url_1 = "/test1";
const char *test_url_2 = "/test2";
const char *test_url_3 = "/test3";
const char *test_response = "test";
void test_get(const http::request_cb_t &&callback, speedy::Speedy &app) {
app.get(test_url_3, callback);
}
void test_post(const http::request_cb_t &&callback, speedy::Speedy &app) {
app.post(test_url_3, callback);
}
void test_put(const http::request_cb_t &&callback, speedy::Speedy &app) {
app.put(test_url_3, callback);
}
void test_delete(const http::request_cb_t &&callback, speedy::Speedy &app) {
app.del(test_url_3, callback);
}
auto test_callback = [](http::Request& req, http::Response& res) {
res.send(test_response);
};
int main(void)
{
// speedy init
uv::UvLoop loop;
http::Ipv4 ip("0.0.0.0", 3400);
speedy::Speedy app(loop);
// GET methods
app.get(test_url_1, test_callback);
app.get(test_url_2, [](http::Request& req, http::Response& res) {
res.send(test_response);
});
test_get(test_callback, app);
// POST examples
app.post(test_url_1, test_callback);
app.post(test_url_2, [](http::Request& req, http::Response& res) {
res.send(test_response);
});
test_post(test_callback, app);
// PUT examples
app.put(test_url_1, test_callback);
app.put(test_url_2, [](http::Request& req, http::Response& res) {
res.send(test_response);
});
test_put(test_callback, app);
// DELETE examples
app.del(test_url_1, test_callback);
app.del(test_url_2, [](http::Request& req, http::Response& res) {
res.send(test_response);
});
test_delete(test_callback, app);
// app run
app.listen(ip);
loop.run(uv::UvLoop::Mode::Default);
return 0;
}