#include <iostream>
#include <native/native.h>
#include <cstdio>
#include <cstring>
//using namespace native::http;

using native::http::http;
using native::http::response;
using native::http::request;
using native::http::url_obj;
using native::run;

int main() {
    http server;
    unsigned short port = 8080;
    if(!server.listen("0.0.0.0", port, [](request& req, response& res) {
        std::cout << "req.url().path() = " << req.url().path();
        if (true) { //strcmp(req.url().path() == "/foo")) {
            std::string body = req.get_body();
            res.set_status(200);
            res.set_header("Content-Type", "application/json");
            res.end(req.url().path());    // Easy way to print current route
        } else {
            std::string body = req.get_body();
            res.set_status(201);
            res.set_header("Content-Type", "application/json");
            res.end("{\"bar\": \"foo\"}");
        }
    })) return 1; // Failed to run server.

    std::cout << "Server running at http://0.0.0.0:" << port << "/" << std::endl;
    return run();
}