properly handle API requests sleep period

 15th February 2024 at 12:33am

The API has a maximum request rate of 1 request/second.

A quick fix.

; sends the request and gets the JSON response
; URIString -> intarweb#response
(define (get-response-from-endpoint endpoint)
  (log-message 0 (string-append "Sleeping before GET request to " endpoint))
  (process-sleep 1)
  (log-message 1 (string-append "Sending GET request to " endpoint))
  (handle-exceptions exn
				   (begin
					 (let ((exn-message ((condition-property-accessor 'exn 'message) exn)))
						 (log-message 5 exn-message))
					 #f)
  					(with-input-from-request
					  (make-request-to-endpoint API-KEY (create-api-uri-object endpoint)) #f read-json)
				   ))

This makes the request only after waiting a second. Very useless if it's only one request to be done; but that's the nature of a quick fix: works, but could be better. I might try a more interesting solution sometime later.