]> gitweb.factorcode.org Git - factor.git/blob - basis/http/http-docs.factor
http: update docs
[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 name" } }
39     { { $slot "content-encoding" } { "an encoding descriptor. See " { $link "io.encodings" } } }
40     { { $slot "body" } { "an HTTP response body" } }
41 } } ;
42
43 HELP: <raw-response>
44 { $values { "response" raw-response } }
45 { $description "Creates an empty raw response." } ;
46
47 HELP: raw-response
48 { $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."
49 $nl
50 "Instances contain the following slots:"
51 { $table
52     { { $slot "version" } { "The HTTP version. Default is " { $snippet "1.1" } " and should not be changed without good reason." } }
53     { { $slot "code" } { "HTTP status code, an " { $link integer } ". Examples are 200 for success, 404 for file not found, and so on." } }
54     { { $slot "message" } { "HTTP status message, only displayed to the user. If the status code is 200, the status message might be “Success”, for example." } }
55     { { $slot "body" } { "an HTTP response body" } }
56 } } ;
57
58 HELP: <cookie>
59 { $values { "value" object } { "name" string } { "cookie" cookie } }
60 { $description "Creates a cookie with the specified name and value. The value can be any object supported by the " { $link present } " word." } ;
61
62 HELP: cookie
63 { $class-description
64 "An HTTP cookie."
65 $nl
66 "Instances contain a number of slots which correspond exactly to the fields of a cookie in the cookie specification:"
67 { $table
68     { { $slot "name" } { "The cookie name, a " { $link string } } }
69     { { $slot "value" } { "The cookie value, an object supported by " { $link present } } }
70     { { $slot "comment" } { "A " { $link string } } }
71     { { $slot "path" } { "The pathname prefix where the cookie is valid, a " { $link string } } }
72     { { $slot "domain" } { "The domain name where the cookie is valid, a " { $link string } } }
73     { { $slot "expires" } { "The expiry time, a " { $link timestamp } " or " { $link f } " for a session cookie" } }
74     { { $slot "max-age" } { "The expiry duration, a " { $link duration } " or " { $link f } " for a session cookie" } }
75     { { $slot "http-only" } { "If set to a true value, JavaScript code cannot see the cookie" } }
76     { { $slot "secure" } { "If set to a true value, the cookie is only sent for " { $snippet "https" } " protocol connections" } }
77 }
78 "Only one of " { $snippet "expires" } " and " { $snippet "max-age" } " can be set; the latter is preferred and is supported by all modern browsers." } ;
79
80 HELP: delete-cookie
81 { $values { "request/response" "a " { $link request } " or a " { $link response } } { "name" string } }
82 { $description "Deletes a cookie from a request or response." }
83 { $side-effects "request/response" } ;
84
85 HELP: get-cookie
86 { $values { "request/response" "a " { $link request } " or a " { $link response } } { "name" string } { "cookie/f" { $maybe cookie } } }
87 { $description "Gets a named cookie from a request or response." } ;
88
89 HELP: put-cookie
90 { $values { "request/response" "a " { $link request } " or a " { $link response } } { "cookie" cookie } }
91 { $description "Stores a cookie in a request or response." }
92 { $side-effects "request/response" } ;
93
94 HELP: <post-data>
95 { $values { "content-type" "a MIME type string" } { "post-data" post-data } }
96 { $description "Creates a new " { $link post-data } "." } ;
97
98 HELP: header
99 { $values { "request/response" "a " { $link request } " or a " { $link response } } { "key" string } { "value" string } }
100 { $description "Obtains an HTTP header value from a request or response." } ;
101
102 HELP: post-data
103 { $class-description "HTTP POST data passed in a POST request."
104 $nl
105 "Instances contain the following slots:"
106 { $table
107     { { $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" } }
108     { { $slot "params" } { "Parameters passed in the POST request." } } 
109     { { $slot "content-type" } { "A MIME type" } }
110     { { $slot "content-encoding" } { "Encoding used for the POST data" } }
111 } } ;
112
113 HELP: set-header
114 { $values { "request/response" "a " { $link request } " or a " { $link response } } { "value" object } { "key" string } }
115 { $description "Stores a value into the HTTP header of a request or response. The value can be any object supported by " { $link present } "." }
116 { $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." }
117 { $side-effects "request/response" } ;
118
119 HELP: set-basic-auth
120 { $values { "request" request } { "username" string } { "password" string } }
121 { $description "Sets the " { $snippet "Authorization" } " header of " { $snippet "request" } " to perform HTTP Basic authentication with the given " { $snippet "username" } " and " { $snippet "password" } "." }
122 { $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." }
123 { $side-effects "request" } ;
124
125 ARTICLE: "http.cookies" "HTTP cookies"
126 "Every " { $link request } " and " { $link response } " instance can contain cookies."
127 $nl
128 "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."
129 $nl
130 "The class of cookies:"
131 { $subsections cookie }
132 "Creating cookies:"
133 { $subsections <cookie> }
134 "Getting, adding, and deleting cookies in " { $link request } " and " { $link response } " objects:"
135 { $subsections
136     get-cookie
137     put-cookie
138     delete-cookie
139 } ;
140
141 ARTICLE: "http.headers" "HTTP headers"
142 "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."
143 { $subsections
144     header
145     set-header
146 } ;
147
148 ARTICLE: "http.post-data" "HTTP post data"
149 "Every " { $link request } " where the " { $slot "method" } " slot is " { $snippet "POST" } " can contain post data."
150 { $subsections
151     post-data
152     <post-data>
153 } ;
154
155 ARTICLE: "http.requests" "HTTP requests"
156 "HTTP requests:"
157 { $subsections
158     request
159     <request>
160 }
161 "Requests can contain form submissions:"
162 { $subsections "http.post-data" } ;
163
164 ARTICLE: "http.responses" "HTTP responses"
165 "HTTP responses:"
166 { $subsections
167     response
168     <response>
169 }
170 "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" } ":"
171 { $subsections
172     raw-response
173     <raw-response>
174 } ;
175
176 ARTICLE: "http" "HTTP protocol objects"
177 "The " { $vocab-link "http" } " vocabulary contains data types shared by " { $vocab-link "http.client" } " and " { $vocab-link "http.server" } "."
178 $nl
179 "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."
180 { $subsections
181     "http.requests"
182     "http.responses"
183 }
184 "Both requests and responses support some common functionality:"
185 { $subsections
186     "http.headers"
187     "http.cookies"
188 }
189 { $see-also "urls" } ;
190
191 ABOUT: "http"