0

The HTTP.jl library provides the function HTTP.request with the following signature HTTP.request(method, url [, headers [, body]]; <keyword arguments>])

I am not sure what this syntax mean url [, headers [, body]]

In particular, what I am trying to do is make a GET request like: https://example.org/api?api_key=my_api_key so I am calling: HTTP.request("GET", "https://example.org/api")

Now how do I specify my api_key in the header?

3
  • the notation using square brackets is very common in programming in general, to indicate optional arguments, and with angle brackets to indicate required arguments, where these need to be denoted as such explicitly. With regard to your particular example, you can either call this method like request(method, url) or like request(method, url, headers) or like request(method, url, headers, body), but not request(method, url, body) for example. Also, you're missing a square bracket above, so I don't know whether keyword arguments are optional in themselves or required if a header is used. Commented Jun 12, 2018 at 12:35
  • Note that this notation is one describing 'syntax' and is intended for human users, this is not "code". You can confirm this notation refers to optional positional arguments and optional keyword arguments if you look up the function definition on line 296 in the link you just posted. Commented Jun 12, 2018 at 12:38
  • @TasosPapastylianou I am sorry. I am fairly new to programming and didn't know this notation. Thanks! Commented Jun 13, 2018 at 5:13

1 Answer 1

1

You would do this like this:

julia HTTP.request("GET", "https://example.org/api"; query = Dict(:api_key => "my_api_key"))

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

2 Comments

Ahh! I was passing this query parameter directly as in HTTP.request("GET", "https://example.org/api", Dict(:api_key => "my_api_key")) because I thought it is not a keyword argument. Thank you!
@kishlaya note that in julia, keyword arguments can be distinguished from positional ones in the function definition because they are separated by a semicolon. When you're calling the function you can use the same syntax, but you don't have to, and you can simply use a comma before the first keyword argument instead; but using a semicolon is just good style.

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.