Main  /  Edit  /  History  /   /  Users Area

CppCMS 1.2 URL Dispatching

CppCMS 1.1 introduced improved url dispatching methods url_dispatcher::map. Following improvements provided over current url_dispatcher::assign

For example:

class my_app : public cppcms::application{
public:
   // ordinary API 
   // name - is validated for correct encoding
   // id converted from string
   void page(int id,std::string const &name);

   // RESTful API
   void new_todo()
   void get_todo(int id);
   void update_todo(int id);
   ...
   my_app(...)
   {
     dispatcher().map("/page/(\\d+)(/(.*))?",
                       &my_app::page,this,1,3);
     dispatcher().map("GET","/todo/(\\d+)",
                       &my_app::get_todo,this,1);
     dispatcher().map("PUT","/todo/(\\d+)",
                       &my_app::update_todo,this,1);
     dispatcher().map("POST","/todo",
                       &my_app::new_todo,this);

   }
};

It is also possible to pass booster::regex object so additional options can be specified:

For example for a function:

void article(std::string const &first_char,std::string const &full_name);

We can specify complex regular expression:

using booster::regex;
dispatcher().map(
   booster::regex("/page/((.).*)",regex::icase | regex::utf8),
   &my_app::article,this,2,1);

So it would match both "/Page/русский" and "/page/русский" and also select a first UTF-8 character "р" properly.

About

CppCMS is a web development framework for performance demanding applications.

Support This Project

SourceForge.net Logo

Поддержать проект

CppCMS needs You


Navigation

Main Page


Valid CSS | Valid XHTML 1.0