What is the equivalent Julia code for this code in Python using requests?

In attempt to use a new service that provides plenty of Python examples, I would like to know the equivalent to the following in Julia. Hopefully I can then work through the remaining examples myself:

import requests

headers = { 
  "apikey": "c1a274360-9ebf-11eb-86374-ffd0a6421e7d"}

params = (
    ("type","prematch"),
 );

response = requests.get('https://app.sportdataapi.com/api/v1/soccer/odds/120423', headers=headers, params=params);
print(response.text)

Your python example is incomplete. Look dictionary: Collections and Data Structures · The Julia Language and tuples Functions · The Julia Language from the documentation.

1 Like

Sorry, I left out the last part. Thank you for the reference.

This could be helpful

https://juliaweb.github.io/HTTP.jl/stable/public_interface/#HTTP.request

You can do something like this

using HTTP
using JSON3

headers = ["apikey" => "c1a274360-9ebf-11eb-86374-ffd0a6421e7d"]

params = ["type" => "prematch"]

uri = "https://app.sportdataapi.com/api/v1/soccer/odds/120423"

res = HTTP.get(uri, query = params, headers = headers)
res = JSON3.read(res.body)

julia> res
JSON3.Object{Vector{UInt8}, Vector{UInt64}} with 2 entries:
  :query => {…
  :data  => {…
3 Likes