From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.user Subject: Re: http-post Date: Fri, 11 Jan 2013 15:44:44 +0100 Message-ID: <878v7z22zn.fsf@pobox.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1357915504 9184 80.91.229.3 (11 Jan 2013 14:45:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 11 Jan 2013 14:45:04 +0000 (UTC) Cc: guile-user@gnu.org To: gregory benison Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jan 11 15:45:22 2013 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TtfrA-0000xy-RM for guile-user@m.gmane.org; Fri, 11 Jan 2013 15:45:17 +0100 Original-Received: from localhost ([::1]:36565 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ttfqu-0007sh-SI for guile-user@m.gmane.org; Fri, 11 Jan 2013 09:45:00 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:56620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ttfqm-0007rJ-Cw for guile-user@gnu.org; Fri, 11 Jan 2013 09:44:57 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ttfqi-0004FB-My for guile-user@gnu.org; Fri, 11 Jan 2013 09:44:52 -0500 Original-Received: from a-pb-sasl-quonix.pobox.com ([208.72.237.25]:60287 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ttfqi-0004F0-Gn for guile-user@gnu.org; Fri, 11 Jan 2013 09:44:48 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id A6471A12B; Fri, 11 Jan 2013 09:44:47 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=ikbcSz/pk1j53Nt/Qb22NlsTet4=; b=A3OpAA 2YVasVitMU146O1T8HS5Du6bm34PupH1swG9lkTCK1rYuxpXyW8FjsXtKZ7Vyi5D 1sakUVC2VkfoEJRt/AsyhcXZX+N+k9crHuohlUb1JoGTeXCjf2P8/x4GQFfyEycD 6FNKMGME4Qy2oEdqMXBVvjCqcVXAn4sJ8Kmdw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=wrxEHY4IJ/ERfdzZZ+5mV6lnh79jSIuu VHXaO32gruQ7lxLSDo285ULbMv882UMrEdJconfWBby3V1318GvwUy0bQQ4g16aB sVtzu2uJvO1Ks79PofARIlv4XTVEjCL+Zzbqd3xSNQuldnV6y1ESXnCtTGUWikGk LdqVYB2nCvE= Original-Received: from a-pb-sasl-quonix.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 9D9E1A12A; Fri, 11 Jan 2013 09:44:47 -0500 (EST) Original-Received: from badger (unknown [88.160.190.192]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTPSA id 02806A129; Fri, 11 Jan 2013 09:44:46 -0500 (EST) In-Reply-To: (gregory benison's message of "Mon, 16 Apr 2012 20:34:55 -0700") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) X-Pobox-Relay-ID: 71F7DDDA-5BFD-11E2-8DD8-0A4F0E5B5709-02397024!a-pb-sasl-quonix.pobox.com X-detected-operating-system: by eggs.gnu.org: Solaris 10 X-Received-From: 208.72.237.25 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:9841 Archived-At: On Tue 17 Apr 2012 05:34, gregory benison writes: > "More helper procedures for the other common HTTP verbs would be a > good addition to this module. Send your code to ." > > So, I say to guile-user, "here is my code". Thanks! I used it as a base for a patch I just pushed. Guile now has client wrappers for all HTTP verbs except CONNECT. Appending the documentation. A websocket implementation would be nice. > I think the next steps after this patch are to: > - be able to work with a greater variety of encodings; > - since form data of the type "key1=value1&key2=value2..." is so > common in POST bodies, accept post data as key-value pairs represented > by an alist (which would be coerced into a bytevector automatically). Yes this would be good. Want to make a patch? Regards, Andy File: guile.info, Node: Web Client, Next: Web Server, Prev: Responses, Up: Web 7.3.8 Web Client ---------------- `(web client)' provides a simple, synchronous HTTP client, built on the lower-level HTTP, request, and response modules. -- Scheme Procedure: open-socket-for-uri uri Return an open input/output port for a connection to URI. -- Scheme Procedure: http-get uri keyword-arg... -- Scheme Procedure: http-head uri keyword-arg... -- Scheme Procedure: http-post uri keyword-arg... -- Scheme Procedure: http-put uri keyword-arg... -- Scheme Procedure: http-delete uri keyword-arg... -- Scheme Procedure: http-trace uri keyword-arg... -- Scheme Procedure: http-options uri keyword-arg... Connect to the server corresponding to URI and make a request over HTTP, using the appropriate method (`GET', `HEAD', etc.). All of these procedures have the same prototype: a URI followed by an optional sequence of keyword arguments. These keyword arguments allow you to modify the requests in various ways, for example attaching a body to the request, or setting specific headers. The following table lists the keyword arguments and their default values. `#:body #f' `#:port (open-socket-for-uri URI)]' `#:version '(1 . 1)' `#:keep-alive? #f' `#:headers '()' `#:decode-body? #t' `#:streaming? #f' If you already have a port open, pass it as PORT. Otherwise, a connection will be opened to the server corresponding to URI. Any extra headers in the alist HEADERS will be added to the request. If BODY is not #f, a message body will also be sent with the HTTP request. If BODY is a string, it is encoded according to the content-type in HEADERS, defaulting to UTF-8. Otherwise BODY should be a bytevector, or `#f' for no body. Although a message body may be sent with any request, usually only `POST' and `PUT' requests have bodies. If DECODE-BODY? is true, as is the default, the body of the response will be decoded to string, if it is a textual content-type. Otherwise it will be returned as a bytevector. However, if STREAMING? is true, instead of eagerly reading the response body from the server, this function only reads off the headers. The response body will be returned as a port on which the data may be read. Unless KEEP-ALIVE? is true, the port will be closed after the full response body has been read. Returns two values: the response read from the server, and the response body as a string, bytevector, #f value, or as a port (if STREAMING? is true). `http-get' is useful for making one-off requests to web sites. If you are writing a web spider or some other client that needs to handle a number of requests in parallel, it's better to build an event-driven URL fetcher, similar in structure to the web server (*note Web Server::). Another option, good but not as performant, would be to use threads, possibly via par-map or futures. -- http://wingolog.org/