Crow/flask.h

55 lines
921 B
C
Raw Normal View History

#pragma once
#include <string>
#include <functional>
#include <memory>
#include <future>
#include <stdint.h>
2014-04-01 12:25:16 +00:00
#include "http_response.h"
#include "http_server.h"
// TEST
#include <iostream>
2014-03-30 13:53:56 +00:00
namespace flask
{
class Flask
{
public:
Flask()
{
}
2014-04-01 12:25:16 +00:00
response handle()
{
2014-04-01 12:25:16 +00:00
return yameHandler_();
}
2014-04-01 12:25:16 +00:00
template <typename F>
void route(const std::string& url, F f)
{
2014-04-01 12:25:16 +00:00
yameHandler_ = [f]{
return response(f());
};
}
Flask& port(std::uint16_t port)
{
port_ = port;
return *this;
}
2014-03-30 13:53:56 +00:00
void run()
{
Server<Flask> server(this, port_);
server.run();
2014-03-30 13:53:56 +00:00
}
private:
uint16_t port_ = 80;
2014-04-01 12:25:16 +00:00
// Someday I will become real handler!
std::function<response()> yameHandler_;
2014-03-30 13:53:56 +00:00
};
};