doc/book/en/development/devweb/request.rst
branchstable
changeset 5290 15846058378b
parent 5231 40f53867e332
child 5301 f4219a6e62e3
equal deleted inserted replaced
5289:540fa73caac6 5290:15846058378b
     1 The `Request` class (`cubicweb.web`)
     1 The `Request` class (`cubicweb.web`)
     2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     2 ------------------------------------
       
     3 
       
     4 Overview
       
     5 ````````
     3 
     6 
     4 A request instance is created when an HTTP request is sent to the web server.
     7 A request instance is created when an HTTP request is sent to the web server.
     5 It contains informations such as form parameters, user authenticated, etc.
     8 It contains informations such as form parameters, user authenticated, etc.
     6 
     9 
     7 **Globally, a request represents a user query, either through HTTP or not
    10 **Globally, a request represents a user query, either through HTTP or not
    14 * `form`, dictionary containing the values of a web form
    17 * `form`, dictionary containing the values of a web form
    15 * `encoding`, character encoding to use in the response
    18 * `encoding`, character encoding to use in the response
    16 
    19 
    17 But also:
    20 But also:
    18 
    21 
    19 :Session data handling:
    22 * `Session data handling`
       
    23 
    20   * `session_data()`, returns a dictionary containing all the session data
    24   * `session_data()`, returns a dictionary containing all the session data
    21   * `get_session_data(key, default=None)`, returns a value associated to the given
    25   * `get_session_data(key, default=None)`, returns a value associated to the given
    22     key or the value `default` if the key is not defined
    26     key or the value `default` if the key is not defined
    23   * `set_session_data(key, value)`, assign a value to a key
    27   * `set_session_data(key, value)`, assign a value to a key
    24   * `del_session_data(key)`,  suppress the value associated to a key
    28   * `del_session_data(key)`,  suppress the value associated to a key
    25 
    29 
       
    30 *  `Cookies handling`
    26 
    31 
    27 :Cookies handling:
       
    28   * `get_cookie()`, returns a dictionary containing the value of the header
    32   * `get_cookie()`, returns a dictionary containing the value of the header
    29     HTTP 'Cookie'
    33     HTTP 'Cookie'
    30   * `set_cookie(cookie, key, maxage=300)`, adds a header HTTP `Set-Cookie`,
    34   * `set_cookie(cookie, key, maxage=300)`, adds a header HTTP `Set-Cookie`,
    31     with a minimal 5 minutes length of duration by default (`maxage` = None
    35     with a minimal 5 minutes length of duration by default (`maxage` = None
    32     returns a *session* cookie which will expire when the user closes the browser
    36     returns a *session* cookie which will expire when the user closes the browser
    33     window)
    37     window)
    34   * `remove_cookie(cookie, key)`, forces a value to expire
    38   * `remove_cookie(cookie, key)`, forces a value to expire
    35 
    39 
    36 :URL handling:
    40 * `URL handling`
       
    41 
    37   * `url()`, returns the full URL of the HTTP request
    42   * `url()`, returns the full URL of the HTTP request
    38   * `base_url()`, returns the root URL of the web application
    43   * `base_url()`, returns the root URL of the web application
    39   * `relative_path()`, returns the relative path of the request
    44   * `relative_path()`, returns the relative path of the request
    40 
    45 
    41 :And more...:
    46 * `And more...`
       
    47 
    42   * `set_content_type(content_type, filename=None)`, adds the header HTTP
    48   * `set_content_type(content_type, filename=None)`, adds the header HTTP
    43     'Content-Type'
    49     'Content-Type'
    44   * `get_header(header)`, returns the value associated to an arbitrary header
    50   * `get_header(header)`, returns the value associated to an arbitrary header
    45     of the HTTP request
    51     of the HTTP request
    46   * `set_header(header, value)`, adds an arbitrary header in the response
    52   * `set_header(header, value)`, adds an arbitrary header in the response
    54 will be provided by the *frontend* web used (in particular *twisted* as of
    60 will be provided by the *frontend* web used (in particular *twisted* as of
    55 today). For the views or others that are executed on the server side,
    61 today). For the views or others that are executed on the server side,
    56 most of the interface of `Request` is defined in the session associated
    62 most of the interface of `Request` is defined in the session associated
    57 to the client.
    63 to the client.
    58 
    64 
       
    65 Automatic API
       
    66 `````````````
    59 
    67 
    60 XXX autoclass !
    68 The elements we gave in overview for above are built in three layers,
    61 XXX create_entity
    69 from ``cubicweb.req.RequestSessionBase``, ``cubicweb.dbapi.DBAPIRequest`` and
       
    70 ``cubicweb.web.CubicWebRequestBase``.
       
    71 
       
    72 .. autoclass:: cubicweb.req.RequestSessionBase
       
    73    :members:
       
    74 
       
    75 .. autoclass:: cubicweb.dbapi.DBAPIRequest
       
    76    :members:
       
    77 
       
    78 .. autoclass:: cubicweb.web.request.CubicWebRequestBase
       
    79    :members: