1

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.

2 Answers 2

2
(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.

Sign up to request clarification or add additional context in comments.

3 Comments

As the docs say, "the default value is a procedure which extracts the username and password components from the URI", so setting the password with make-uri is definitely suppoted and probably the simplest way in general. This is why with-input-from-request and friends accept either a string, an URI object or a request - you pass in the simplest thing that can work.
@sjamaan maybe you could post that as a 2nd answer if you have the spare time.
OK, I've done that now
2

As the docs say,

the default value is a procedure which extracts the username and password components from the URI"

So, setting the password with make-uri is definitely supported and probably the simplest way in general. This is why with-input-from-request and friends accept either a string, an URI object or a request - you pass in the simplest thing that can work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.