X-Git-Url: http://nitlanguage.org diff --git a/lib/app/http_request.nit b/lib/app/http_request.nit index 8ab0f1d..07d4bf3 100644 --- a/lib/app/http_request.nit +++ b/lib/app/http_request.nit @@ -13,6 +13,23 @@ # limitations under the License. # HTTP request services: `AsyncHttpRequest` and `Text::http_get` +# +# ~~~nitish +# import app::http_request +# +# class MyHttpRequest +# super AsyncHttpRequest +# +# redef fun uri do return "http://example.com/" +# +# redef fun on_load(data, status) do print "Received: {data or else "null"}" +# +# redef fun on_fail(error) do print "Connection error: {error}" +# end +# +# var req = new MyHttpRequest +# req.start +# ~~~ module http_request import app_base @@ -122,9 +139,14 @@ abstract class AsyncHttpRequest fun after do end end -# Minimal implementation of `AsyncHttpRequest` where `uri` is an attribute +# Simple `AsyncHttpRequest` where `uri` is an attribute +# +# Prints on communication errors and when the remote server returns an +# HTTP status code not in the 200s. # -# Prints on communication errors and when the server returns an HTTP status code not in the 200s. +# This class can be instantiated to execute a request where the response is +# ignored by the application. Alternatively, it can be subclassed to implement +# `on_load`. # # ~~~nitish # var request = new SimpleAsyncHttpRequest("http://example.com")