]> 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 "raw" } { "The raw bytes of the POST data" } }
107     { { $slot "content" } { "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 "content-type" } "A MIME type" }
109 } } ;
110
111 HELP: set-header
112 { $values { "request/response" "a " { $link request } " or a " { $link response } } { "value" object } { "key" string } }
113 { $description "Stores a value into the HTTP header of a request or response. The value can be any object supported by " { $link present } "." }
114 { $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." }
115 { $side-effects "request/response" } ;
116
117 HELP: set-basic-auth
118 { $values { "request" request } { "username" string } { "password" string } }
119 { $description "Sets the " { $snippet "Authorization" } " header of " { $snippet "request" } " to perform HTTP Basic authentication with the given " { $snippet "username" } " and " { $snippet "password" } "." }
120 { $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." }
121 { $side-effects "request" } ;
122
123 ARTICLE: "http.cookies" "HTTP cookies"
124 "Every " { $link request } " and " { $link response } " instance can contain cookies."
125 $nl
126 "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."
127 $nl
128 "The class of cookies:"
129 { $subsections cookie }
130 "Creating cookies:"
131 { $subsections <cookie> }
132 "Getting, adding, and deleting cookies in " { $link request } " and " { $link response } " objects:"
133 { $subsections
134     get-cookie
135     put-cookie
136     delete-cookie
137 } ;
138
139 ARTICLE: "http.headers" "HTTP headers"
140 "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."
141 { $subsections
142     header
143     set-header
144 } ;
145
146 ARTICLE: "http.post-data" "HTTP post data"
147 "Every " { $link request } " where the " { $slot "method" } " slot is " { $snippet "POST" } " can contain post data."
148 { $subsections
149     post-data
150     <post-data>
151 } ;
152
153 ARTICLE: "http.requests" "HTTP requests"
154 "HTTP requests:"
155 { $subsections
156     request
157     <request>
158 }
159 "Requests can contain form submissions:"
160 { $subsections "http.post-data" } ;
161
162 ARTICLE: "http.responses" "HTTP responses"
163 "HTTP responses:"
164 { $subsections
165     response
166     <response>
167 }
168 "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" } ":"
169 { $subsections
170     raw-response
171     <raw-response>
172 } ;
173
174 ARTICLE: "http" "HTTP protocol objects"
175 "The " { $vocab-link "http" } " vocabulary contains data types shared by " { $vocab-link "http.client" } " and " { $vocab-link "http.server" } "."
176 $nl
177 "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."
178 { $subsections
179     "http.requests"
180     "http.responses"
181 }
182 "Both requests and responses support some common functionality:"
183 { $subsections
184     "http.headers"
185     "http.cookies"
186 }
187 { $see-also "urls" } ;
188
189 ABOUT: "http"