mengdilin / cjango-unchained Goto Github PK
View Code? Open in Web Editor NEWLightweight Web App Framework In C++
Lightweight Web App Framework In C++
HttpResponse response = HttpResponse();
response.write("<p>Here's the text of the Web page.</p>");
response.write("<p>Here's another paragraph.</p>");
reference:
Router.add("/abc", some call back);
Router.add("/efg", some call back);
Router.add("/xyz", some call back);
//patterns_list should have the patterns in the order: ["/abc", "/efg", "/xyz"]
Router(map<string, functor> routes)
: constructor that calls add_route
to populate pattern_to_callback and patterns_list.
add_route(string url_pattern, functor callback)
: callback must have the signature HttpResponse f(HttpRequest)
. Given a url_pattern
and a callback
functor, we store this pair in pattern_to_callback
member variable and update patterns_list
. We throw an error if we are trying to register the same url_pattern
with different callback
functors. Note, url_pattern
may be a regex pattern or an actual url_path.
string resolve(HttpRequest)
: given a http request, it returns the url_pattern corresponding to the http request. Example: a request for "/abc/e" will return "/abc/e". resolve
becomes more complicated if we allow regex resolution.
HttpResponse get_http_response(HttpRequest)
: given a http request, it returns the corresponding http response.
pseudo code:
HttpResponse get_http_response(HttpRequest request) {
string url_path = resolve(request);
functor callback = pattern_to_callback.find(url_path);
return callback(request):
}
Note, have to handle casese if resolve cannot find any url_path, this would be a "404 Not Found" response. We perhaps will have helper functions for constructing these error responses.
run(int port)
: runs forever on a given port.
handle_request(client socket)
handle_request(client socket)
: given a client socket, it reads the raw http request string from the socket, creates a HttpRequest
object given the raw string, gets callback function by calling resolve(HttpRequest)
on the newly created http request object, and sends back a http response corresponding to the request back to the client socket.App(map<string, functor> routes)
: app constructor that takes a map of url path to functor.
http/version
or https/version
). For simplicity sake, we only support http/1.0
; thus, scheme is always set to http/1.0
."GET", "POST", "HEAD"
Set-Cookie:name=value
Cookie:name=value
reference:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.