Home > Software design >  How do I use HTTP Basic Auth with http-client?
How do I use HTTP Basic Auth with http-client?

Time:07-13

I want to use http-client to make an HTTP request equivalent to:

curl -u 'user:pass' 'https://api.example.net/a/b/c'

I have read the docs for http-client, as well as for intarweb and uri-common, but I am still unsure of how to achieve this.

I can see that it's possible to set a username and password with make-uri, but I'm not sure if that's the best option.

I'm open to multiple solutions if there is more than one way to do it, but an idiomatic answer is preferable.

CodePudding user response:

(define user "user")
(define pass "pass")

(determine-username/password
 (lambda (uri realm)
   (values user pass)))

See https://wiki.call-cc.org/eggref/5/http-client#authentication-support for the technical details.

  • Related