Class: Waxx::Req
- Inherits:
-
Struct
- Object
- Struct
- Waxx::Req
- Defined in:
- waxx/req.rb
Overview
The Request Struct gets instanciated with each request (x.req) “` x.req.env # A hash of the request environment x.req.data # The raw body of put, post, patch requests x.req.meth # Request method as a string: GET, PUT, POST, PATCH, DELETE x.req.uri # The URI x.req.get # The GET/URL parameters (has with string keys and values) shortcut: x => 'value' x.req.post # The POST/BODY params with string keys and values) shortcut: x => 'value' “`
GET params can be delimited with & or ;. The following are equivilant:
“` localhost:7777/waxx/env?x=1&y=2&z=3 localhost:7777/waxx/env?x=1;y=2;z=3 “`
Note that single params are single values and will be set to the last value received. Params names with “[]” appended are array values.
“` localhost:7777/waxx/env?foo=1;foo=2;foo=3 x => “3”
localhost:7777/waxx/env?foo[]=1;foo[]=2;foo[]=3 x => [“1”, “2”, “3”]
“` If you are uploading JSON directly in the body (with the content type application/json or text/json), then the types are matched.
Given the a request like:
“` Content-Type: application/json
'a “`
The following vars are of the type submitted
“` x => 123 (as an int) x => ['a','1',2] (1 is a string and 2 is an int) “`
### File Uploads Given the form:
“` <form action=“/file/upload” method=“post” enctype=“multipart/form-data”>
<input type="file" name="file">
<button type="submit">Upload File</button>
</form> “`
The following hash is available (symbol keys):
“` x[:filename] => 'file_name.ext' x[:data] => The content of the file x[:content_type] => The Content-Type as sent by the browser x[:headers] => An hash of other headers send by the browser regarding this file “`
How to save a file to the tmp folder:
*app/file/file.rb*
“` module App::File
extend Waxx::Object
runs(
upload: {
desc: 'Upload a file to the tmp folder',
post: -> (x) {
# Strip any non-word chars and save the file to the tmp folder
File.open("#{Waxx::Root}/tmp/(x/:file/:filename).gsub(/[\W\.]/,'-'),'wb'){|f|
f << x/:file/:data
}
x << "Your file has been uploaded."
}
}
)
end “`
Instance Attribute Summary collapse
-
#cookies ⇒ Object
Returns the value of attribute cookies.
-
#data ⇒ Object
Returns the value of attribute data.
-
#env ⇒ Object
Returns the value of attribute env.
-
#get ⇒ Object
Returns the value of attribute get.
-
#meth ⇒ Object
Returns the value of attribute meth.
-
#post ⇒ Object
Returns the value of attribute post.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Attribute Details
#cookies ⇒ Object
Returns the value of attribute cookies
104 105 106 |
# File 'waxx/req.rb', line 104 def @cookies end |
#data ⇒ Object
Returns the value of attribute data
104 105 106 |
# File 'waxx/req.rb', line 104 def data @data end |
#env ⇒ Object
Returns the value of attribute env
104 105 106 |
# File 'waxx/req.rb', line 104 def env @env end |
#get ⇒ Object
Returns the value of attribute get
104 105 106 |
# File 'waxx/req.rb', line 104 def get @get end |
#meth ⇒ Object
Returns the value of attribute meth
104 105 106 |
# File 'waxx/req.rb', line 104 def meth @meth end |
#post ⇒ Object
Returns the value of attribute post
104 105 106 |
# File 'waxx/req.rb', line 104 def post @post end |
#start_time ⇒ Object
Returns the value of attribute start_time
104 105 106 |
# File 'waxx/req.rb', line 104 def start_time @start_time end |
#uri ⇒ Object
Returns the value of attribute uri
104 105 106 |
# File 'waxx/req.rb', line 104 def uri @uri end |