]> gitweb.factorcode.org Git - factor.git/blob - basis/http/http-docs.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / http / http-docs.factor
1 USING: assocs help.markup help.syntax io.streams.string sequences strings present math kernel byte-arrays urls
2 calendar ;
3 IN: http
4
5 HELP: <request>
6 { $values { "request" request } }
7 { $description "Creates an empty request." } ;
8
9 HELP: request
10 { $description "An HTTP request."
11 $nl
12 "Instances contain the following slots:"
13 { $table
14     { { $slot "method" } { "The HTTP method as a " { $link string } ". The most frequently-used HTTP methods are " { $snippet "GET" } ", " { $snippet "HEAD" } " and " { $snippet "POST" } "." } }
15     { { $slot "url" } { "The " { $link url } " being requested" } }
16     { { $slot "version" } { "The HTTP version. Default is " { $snippet "1.1" } " and should not be changed without good reason." } }
17     { { $slot "header" } { "An assoc of HTTP header values. See " { $link "http.headers" } } }
18     { { $slot "post-data" } { "See " { $link "http.post-data" } } }
19     { { $slot "cookies" } { "A sequence of HTTP cookies. See " { $link "http.cookies" } } }
20     { { $slot "redirects" } { "Number of redirects to attempt before throwing an error. Default is " { $snippet "max-redirects" } " ." } }
21 } } ;
22
23 HELP: <response>
24 { $values { "response" response } }
25 { $description "Creates an empty response." } ;
26
27 HELP: response
28 { $class-description "An HTTP response."
29 $nl
30 "Instances contain the following slots:"
31 { $table
32     { { $slot "version" } { "The HTTP version. Default is " { $snippet "1.1" } " and should not be changed without good reason." } }
33     { { $slot "code" } { "HTTP status code, an " { $link integer } ". Examples are 200 for success, 404 for file not found, and so on." } }
34     { { $slot "message" } { "HTTP status message, only displayed to the user. If the status code is 200, the status message might be “Success”, for example." } }
35     { { $slot "header" } { "An assoc of HTTP header values. See " { $link "http.headers" } } }
36     { { $slot "cookies" } { "A sequence of HTTP cookies. See " { $link "http.cookies" } } }
37     { { $slot "content-type" } { "an HTTP content type" } }
38     { { $slot "content-charset" } { "an encoding descriptor. See " { $link "io.encodings" } } }
39     { { $slot "body" } { "an HTTP response body" } }
40 } } ;
41
42 HELP: <raw-response>
43 { $values { "response" raw-response } }
44 { $description "Creates an empty raw response." } ;
45
46 HELP: raw-response
47 { $class-description "A minimal HTTP response used by webapps which need full control over all output sent to the client. Most webapps can use " { $link response } " instead."
48 $nl
49 "Instances contain the following slots:"
50 { $table
51     { { $slot "version" } { "The HTTP version. Default is " { $snippet "1.1" } " and should not be changed without good reason." } }
52     { { $slot "code" } { "HTTP status code, an " { $link integer } ". Examples are 200 for success, 404 for file not found, and so on." } }
53     { { $slot "message" } { "HTTP status message, only displayed to the user. If the status code is 200, the status message might be “Success”, for example." } }
54     { { $slot "body" } { "an HTTP response body" } }
55 } } ;
56
57 HELP: <cookie>
58 { $values { "value" object } { "name" string } { "cookie" cookie } }
59 { $description "Creates a cookie with the specified name and value. The value can be any object supported by the " { $link present } " word." } ;
60
61 HELP: cookie
62 { $class-description
63 "An HTTP cookie."
64 $nl
65 "Instances contain a number of slots which correspond exactly to the fields of a cookie in the cookie specification:"
66 { $table
67     { { $slot "name" } { "The cookie name, a " { $link string } } }
68     { { $slot "value" } { "The cookie value, an object supported by " { $link present } } }
69     { { $slot "comment" } { "A " { $link string } } }
70     { { $slot "path" } { "The pathname prefix where the cookie is valid, a " { $link string } } }
71     { { $slot "domain" } { "The domain name where the cookie is valid, a " { $link string } } }
72     { { $slot "expires" } { "The expiry time, a " { $link timestamp } " or " { $link f } " for a session cookie" } }
73     { { $slot "max-age" } { "The expiry duration, a " { $link duration } " or " { $link f } " for a session cookie" } }
74     { { $slot "http-only" } { "If set to a true value, JavaScript code cannot see the cookie" } }
75     { { $slot "secure" } { "If set to a true value, the cookie is only sent for " { $snippet "https" } " protocol connections" } }
76 }
77 "Only one of " { $snippet "expires" } " and " { $snippet "max-age" } " can be set; the latter is preferred and is supported by all modern browsers." } ;
78
79 HELP: delete-cookie
80 { $values { "request/response" "a " { $link request } " or a " { $link response } } { "name" string } }
81 { $description "Deletes a cookie from a request or response." }
82 { $side-effects "request/response" } ;
83
84 HELP: get-cookie
85 { $values { "request/response" "a " { $link request } " or a " { $link response } } { "name" string } { "cookie/f" { $maybe cookie } } }
86 { $description "Gets a named cookie from a request or response." } ;
87
88 HELP: put-cookie
89 { $values { "request/response" "a " { $link request } " or a " { $link response } } { "cookie" cookie } }
90 { $description "Stores a cookie in a request or response." }
91 { $side-effects "request/response" } ;
92
93 HELP: <post-data>
94 { $values { "content-type" "a MIME type string" } { "post-data" post-data } }
95 { $description "Creates a new " { $link post-data } "." } ;
96
97 HELP: header
98 { $values { "request/response" "a " { $link request } " or a " { $link response } } { "key" string } { "value" string } }
99 { $description "Obtains an HTTP header value from a request or response." } ;
100
101 HELP: post-data
102 { $class-description "HTTP POST data passed in a POST request."
103 $nl
104 "Instances contain the following slots:"
105 { $table
106     { { $slot "data" } { "The POST data. This can be in a higher-level form, such as an assoc of POST parameters, a string, or an XML document" } }
107     { { $slot "params" } { "Parameters passed in the POST request." } } 
108     { { $slot "content-type" } { "A MIME type" } }
109     { { $slot "content-encoding" } { "Encoding used for the POST data" } }
110 } } ;
111
112 HELP: set-header
113 { $values { "request/response" "a " { $link request } " or a " { $link response } } { "value" object } { "key" string } }
114 { $description "Stores a value into the HTTP header of a request or response. The value can be any object supported by " { $link present } "." }
115 { $notes "This word always returns the same object that was input. This allows for a “pipeline” coding style, where several header parameters are set in a row." }
116 { $side-effects "request/response" } ;
117
118 HELP: set-basic-auth
119 { $values { "request" request } { "username" string } { "password" string } }
120 { $description "Sets the " { $snippet "Authorization" } " header of " { $snippet "request" } " to perform HTTP Basic authentication with the given " { $snippet "username" } " and " { $snippet "password" } "." }
121 { $notes "This word always returns the same object that was input. This allows for a “pipeline” coding style, where several header parameters are set in a row." }
122 { $side-effects "request" } ;
123
124 ARTICLE: "http.cookies" "HTTP cookies"
125 "Every " { $link request } " and " { $link response } " instance can contain cookies."
126 $nl
127 "The " { $vocab-link "furnace.sessions" } " vocabulary implements session management using cookies, thus the most common use case can be taken care of without working with cookies directly."
128 $nl
129 "The class of cookies:"
130 { $subsections cookie }
131 "Creating cookies:"
132 { $subsections <cookie> }
133 "Getting, adding, and deleting cookies in " { $link request } " and " { $link response } " objects:"
134 { $subsections
135     get-cookie
136     put-cookie
137     delete-cookie
138 } ;
139
140 ARTICLE: "http.headers" "HTTP headers"
141 "Every " { $link request } " and " { $link response } " has a set of HTTP headers stored in the " { $slot "header" } " slot. Header names are normalized to lower-case when a request or response is being parsed."
142 { $subsections
143     header
144     set-header
145 } ;
146
147 ARTICLE: "http.post-data" "HTTP post data"
148 "Every " { $link request } " where the " { $slot "method" } " slot is " { $snippet "POST" } " can contain post data."
149 { $subsections
150     post-data
151     <post-data>
152 } ;
153
154 ARTICLE: "http.requests" "HTTP requests"
155 "HTTP requests:"
156 { $subsections
157     request
158     <request>
159 }
160 "Requests can contain form submissions:"
161 { $subsections "http.post-data" } ;
162
163 ARTICLE: "http.responses" "HTTP responses"
164 "HTTP responses:"
165 { $subsections
166     response
167     <response>
168 }
169 "Raw responses only contain a status line, with no header. They are used by webapps which need full control over the HTTP response, for example " { $vocab-link "http.server.cgi" } ":"
170 { $subsections
171     raw-response
172     <raw-response>
173 } ;
174
175 ARTICLE: "http" "HTTP protocol objects"
176 "The " { $vocab-link "http" } " vocabulary contains data types shared by " { $vocab-link "http.client" } " and " { $vocab-link "http.server" } "."
177 $nl
178 "The HTTP client sends an HTTP request to the server and receives an HTTP response back. The HTTP server receives HTTP requests from clients and sends HTTP responses back."
179 { $subsections
180     "http.requests"
181     "http.responses"
182 }
183 "Both requests and responses support some common functionality:"
184 { $subsections
185     "http.headers"
186     "http.cookies"
187 }
188 { $see-also "urls" } ;
189
190 ABOUT: "http"