import std/[httpclient, json, logging, uri]

proc fetchPassages*(reference, apiToken, apiRoot: string): seq[string] =
  let http = newHttpClient()
  http.headers = newHttpHeaders({"Authorization": "Token " & apiToken})

  let urlPath = apiRoot & "/v3/passage/text/?q=" & encodeUrl(reference)
  debug "requesting " & urlPath

  let respJson = parseJson(http.getContent(urlPath))
  result = @[]
  for passage in respJson["passages"].getElems:
    result.add(passage.getStr)
