共用方式為


http_request 函式

適用於:勾選為 yes Databricks SQL 勾選為 yes Databricks Runtime 16.2 及以上版本

使用定義的 HTTP 連線 發出HTTP 請求。

此函式需要具名參數調用。

語法

http_request( { CONN => connectionName |
                METHOD => httpMethod |
                PATH => path |
                HEADERS => headerMap |
                PARAMS => paramMap |
                JSON => jsonStr  } [, ..] )

論點

如果指定參數一次以上,就會引發錯誤。

  • connectionName

    用於參考現有 HTTP 連線識別碼的 STRING 常數。 需要此參數

  • httpMethod

    STRING 常數運算式用來表示所使用的 HTTP 方法。 支援下列方法:『GET』、『POST』、『PUT』、『DELETE』、『PATCH』。 這個參數是必需的。

  • path

    附加至連線 URL 的常數運算式。 路徑不得包含目錄周游 (../..)。 這個參數是必需的。

  • headerMap

    包含請求標頭的選擇性 MAP<STRING, STRING>。 預設值為 NULL

  • paramMap

    可選的 MAP<STRING, STRING>,包含以 JSON 格式表示的查詢參數。 預設值為 NULL

  • jsonStr

    具有要求主體的選擇性 JSON 字串表達式。

退貨

一個 STRUCT<status_code INT, text STRING> 的地方

  • status_code 是來自外部服務的回應 HTTP 狀態代碼。 例如:200 或 403。
  • text 是外部服務傳回的回應。 一般而言,這是 JSON 字串。

例子

-- Set up a connect to Slack.
> CREATE CONNECTION slack_conn
  TYPE HTTP
  OPTIONS (
    host 'https://slack.com',
    port '443',
    base_path '/api/',
    bearer_token 'xoxb-xxxxx'
  );

-- Request to the external service
> SELECT http_request(
    conn => 'slack_conn',
    method => 'POST',
    path => '/chat.postMessage',
    json => to_json(named_struct(
      'channel', channel,
      'text', text
    ))
    headers => map(
       'Accept', "application/vnd.github+json",
    )
  );