File: libraries.md

package info (click to toggle)
lua-wsapi 1.1.0-8
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 400 kB
  • ctags: 171
  • sloc: ansic: 613; sh: 100; makefile: 30
file content (63 lines) | stat: -rw-r--r-- 2,316 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
## Overview

WSAPI includes a set of helper libraries to make writing applications and web frameworks easier.
To use these libraries just `require` them in your application or framework.

## Request

**wsapi.request.new(*wsapi_env*, [*options*])** - creates a new request object wrapping *wsapi_env*; *options* is an (optional) table of extra options
for the request, the only option currently supported is *delay_post*, if set
this won't process the POST data on creation of the request

**req:parse_post_data()** - processed the POST data in case the processing
was delayed by passing *delay_post = true* on creation of the request

**req.GET** - table with GET parameters of request

**req.POST** - table with POST parameters of request

**req.method** - request method (usually "GET" or "POST") 

**req.path_info** - PATH_INFO metavariable

**req.script_name** - SCRIPT_NAME metavariable

**req.query_string** - unparsed query string

**req.params** - union of **req.GET** and **req.POST**, built on demand

**req.cookies[*name*]** - gets value of a cookie from browser

## Response

**wsapi.response.new([*status*, *headers*, *body*])** - creates a new response
object, optionally setting an initial status code, header table and body contents

**res.status** - status code to be returned to server

**res.headers** - table with headers to be returned to server

**res[*name*]** - same as **res.headers[*name*]**, unless *name* is a field in res

**res[*name*] = _value_** - same as **res.headers[*name*] = _value_**, unless *name* is
a field in res

**res:write(*s*)** - adds *s* to the body if it is a string, if it is a table
concatenate the contents of the table and add to the body

**res:set_cookie(*name*, *value*)** - sets the value of a cookie

**res:delete_cookie(*name*)** - erases a cookie from browser

**res:finish()** - finishes response, returning status, headers and an iterator for the body

## Util

**wsapi.util.url_encode(*s*)** - encodes *s* according to RFC2396

**wsapi.util.url_decode(*s*)** - decodes *s* according to RFC2396

**wsapi.util.make\_rewindable(*wsapi\_env*)** - wraps *wsapi\_env* in a new
environment that lets you process the POST data more than once. This new
environment's input object has a *rewind* method that you can call to allow you to read
the POST data again.