Fastly Compute C++ SDK
Loading...
Searching...
No Matches
router.cpp
#include "fastly/sdk.h"
#include <iostream>
#include <regex>
// NOTE: Please evaluate the SECURITY of this for your own purposes if you base
// your code on this. `std::regex` is vulnerable to ReDOS and is not suitable
// for user-provided regexes. Other vulnerabilities may be present depending on
// your C++ version.
// Routes
const std::regex HOME("^/?$");
const std::regex BOOK_GET("^/books/(\\d+)$");
const std::regex BOOK_LIST("^/books/?$");
int main() {
auto path{req.get_path()};
std::smatch match;
if (std::regex_match(path, match, HOME)) {
body << "Welcome Home!";
} else if (std::regex_match(path, match, BOOK_GET)) {
body << "So you want to get book with ID " << match[1]
<< "? I'll look for it later idk.";
} else if (std::regex_match(path, match, BOOK_LIST)) {
body << "There's a bunch of books. I don't feel like listing them right "
"now. That sounds like a pain.";
} else {
.with_body("Route not found")
return 0;
}
body << std::endl;
}
int main()
Definition async_reqs.cpp:10
static Request from_client()
static Response from_status(StatusCode status)
Create a new response with the given status code.
static Response from_body(Body body)
Create a new Response with the given value as the body.
Definition body.h:42
Response with_body(Body body) &&
Builder-style equivalent of Response::set_body().
const std::regex HOME("^/?$")
const std::regex BOOK_LIST("^/books/?$")
const std::regex BOOK_GET("^/books/(\\d+)$")