v0.1.0-alpha: Merge pull request #73 from valum-framework/0.1/server-documentation
Pre-releaseThis release is the second release of Valum. It is a pre-release since we are still prototyping most of the features and we need feedback and ideas to create the very best Vala web micro-framework.
You can very the release against this SHA1: eceadafe08bbbf52cefeda2ae240825b92223708
Changeset
- complete FastCGI support through Vala bindings for fcgi
- improved Route
- Flask-like typed variables
- regex scoping
- VSGI (Vala Server Gateway Interface)
- based on libsoup
- server implementation for libsoup and FastCGI
- constants for HTTP methods
- user and api documentation
- code coverage
Most of these changes are breaking the initial API as there was a great step between the initial framework and something designed to support any web protocol.
Route and Router improvments
The new variable system for rules is more powerful as it is now possible to type parameters:
app.get("user/<int:id>", (req, res) => {
var id = req.params["id"];
});
app.get ("<any:anything>", (req, res) => {
// catches /.+/
});
The Route
class is more flexible and support literal regular expression that are automatically scoped and anchored with ^
and $
.
app.regex (Request.GET, /home/, (req, res) => {
var writer = new DataOutputStream (res);
writer.put_string ("Matched using a Regex!");
});
Route have been reimplemented upon a matcher callback. This make the routing system is therefore much more powerful.
app.matcher (Request.GET, (req) => { return true; }, (req, res) => {
// catch-all route
});
VSGI
VSGI is a set of abstractions and implementations that aims a compatibility with all existing HTTP. It's heavily based on libsoup-2.4, an library implementing the HTTP protocol.
Request
andResponse
inherit fromInputStream
andOutputStream
respectivelyRequest
provide HTTP methods constantsheaders
based onSoup.MessageHeaders
uri
based onSoup.URI
that provides access to path and HTTP query- basic cookies handling
All implementations are stored un a subnamespace VSGI.*
and respect a common interface. It is possible to switch the used server technology with a using
statement.
using VSGI.FastCGI;
using VSGI.Soup;
The server implementation has been based on GLib.Application
, providing a great host integration and many useful capabilities:
- a
MainLoop
for processing events and asynchronous work - DBus integration
- capability to handle CLI arguments
- optional timeout feature to exit automatically if no requests are received after a certain delay
If the server takes the CLI arguments, it can be parametrized very nicely:
using Valum;
using VSGI.Soup;
public static int main (string[] args) {
var app = new Router ();
return new Server (app).run (args);
}
Code coverage
The framework is released with an overall coverage of 53%.
The coverage for the most important components of the framework (Router
, Route
, View
) is very good, but there is almost nothing for VSGI implementations.
Documentation
Big loads of efforts were put on producing a quality user documentation. It is written in reStructuredText and generated by Sphinx.
You can consult the documentation on ReadTheDocs: http://valum-framework.readthedocs.org/en/latest/
It covers the whole framework, VSGI and provide guidelines and approach to deal with common web development issues.