Commits

Andy Bennett  committed f06d065

Support the header-reader

Provide a way for the caller to extract information from the headers
returned in the response to their API call.

Signed-off-by: Andy Bennett <andyjpb@knodium.com>

  • Participants
  • Parent commits 7f2fe06

Comments (0)

Files changed (2)

File rest-bind.scm

 	     (uri/req  (second defn))
 	     (writer   (third defn))
 	     (reader   (fourth defn))
+	     (header-reader (if (= 5 (length defn)) (fifth defn) #f))
 	     (args     (if writer
 			 `(,@pos-args body)
 			 `(,@pos-args)))
 	;(list 'quote
 	      `(define ,name
 		 (let* ((writer  ,writer)
+			,@(if header-reader `((header-reader ,header-reader)) '())
 			(uri/req ,uri/req)
 			(uri     (cond ((request? uri/req) (request-uri uri/req))
 				       ((uri? uri/req) uri/req)
 				   '())
 			   (req (make-request uri: uri method: method)) ; poke the args into query string.
 			   )
-		       (call-with-input-request req ,(if writer '(writer body) #f) ,reader)))))
+		       (receive (reader uri response)
+				(call-with-input-request req ,(if writer '(writer body) #f) ,reader)
+				,(if header-reader
+					'(values (header-reader (response-headers response)) reader (list uri response))
+					'(values reader (list uri response))))
+				))))
 	      ;)
 	))))
 

File rest-bind.svnwiki

 
 When all the preparations have been made, the URL is then fetched via {{call-with-input-request}} from [[http-client]]. If {{body-writer}} is not specified then the GET method is implied. If {{body-writer}} is specified then the POST method is implied. If the HTTP API calls for another method then {{uri-or-request}} must be specified using {{make-request}} from [[intarweb]]. {{body-reader}} is passed as the {{reader}} argument to {{call-with-input-request}}. The result of {{body-reader}} is one of the results of the call to {{procedure-name}}.
 
-{{procedure-name}} currently returns the result of call-with-input-request.
-
-{{header-reader}} is optional and currently ignored. It is intended that this be a procedure that can extract any required headers from the response.
+When {{header-reader}} is specified, {{procedure-name}} returns three results:
+the result of the call to {{header-reader}}, the result of the call to
+{{reader}} and a list containing the {{uri}} and {{response}} objects. When
+{{header-reader}} is not specified, {{procedure-name}} returns just the latter
+two values.
+
+{{header-reader}} is optional. If it is supplied, it is called as a procedure
+with the response headers as its only argument. The result of the call to this
+procedure is then returned as the first result of the {{procedure-name}} call.
 
 === Examples