Next: , Previous: Responses, Up: Web


7.3.7 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
— Scheme Procedure: http-get uri [#:port=(open-socket-for-uri uri)] [#:version='(1 . 1)] [#:keep-alive?=#f] [#:extra-headers='()] [#:decode-body=#t]

Connect to the server corresponding to uri and ask for the resource, using the GET method. If you already have a port open, pass it as port. The port will be closed at the end of the request unless keep-alive? is true. Any extra headers in the alist extra-headers will be added to the request.

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.

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 (see Web Server).

Another option, good but not as performant, would be to use threads, possibly via par-map or futures.

More helper procedures for the other common HTTP verbs would be a good addition to this module. Send your code to guile-user@gnu.org.