BaseXdb / basex

BaseX Main Repository.
http://basex.org
BSD 3-Clause "New" or "Revised" License
684 stars 265 forks source link

HTTP Module: CSV, JSON, HTML #2232

Closed ChristianGruen closed 1 year ago

ChristianGruen commented 1 year ago

If the output of an EXPath HTTP Client Module request is CSV, JSON or HTML, it is implicitly converted to an XML representation:

http:send-request((), 'http://localhost/csv')
→ <csv>...</csv>

It’s possible to specify conversion options, but it’s not very intuitive:

(: Disable implicit conversion :)
let $response := http:send-request(
  <http:request method='get' override-media-type='application/octet-stream'/>,
  'http://localhost/csv'
)
return csv:parse(
  convert:binary-to-string($response[2]),
  map { 'header': true(), 'separator': 'semicolon' }
)

(: Pragma :)
(# db:csvparser header=true,separator=semicolon #) {
  http:send-request((), 'http://localhost/csv')
}

(: Option declaration :)
declare option db:csvparser 'header=true,separator=semicolon';
http:send-request((), 'http://localhost/csv')

Maybe we can embed the options in the function call. Possible options:

http:send-request(
  <http:request method='get' csv='header=true,separator=semicolon' href='...'/>
)

http:send-request(
  <http:request method='get' href='...'>
    <http:output csv='header=true,separator=semicolon'/>
  </http:request>
)

http:send-request(
  <http:request method='get' href='...'>
    <http:csv header='true' separator='semicolon'/>
  </http:request>
)