套件 google.api

索引

HttpBody

用於表示任何 HTTP 主體的訊息;只能用於無法以 JSON 表示的酬載格式,例如未經處理的二進位檔或 HTML 網頁。

這個訊息可以用於要求及回應中的串流和非串流 API 方法。

這個訊息可以當做頂層要求欄位;想從網址或 HTTP 範本中將參數擷取至要求欄位,同時又想存取未經處理的 HTTP 主體時,這個做法就非常便利。

範例:

message GetResourceRequest {
  // A unique request id.
  string request_id = 1;

  // The raw HTTP body is bound to this field.
  google.api.HttpBody http_body = 2;
}

service ResourceService {
  rpc GetResource(GetResourceRequest) returns (google.api.HttpBody);
  rpc UpdateResource(google.api.HttpBody) returns (google.protobuf.Empty);
}

串流方法範例:

service CaldavService {
  rpc GetCalendar(stream google.api.HttpBody)
    returns (stream google.api.HttpBody);
  rpc UpdateCalendar(stream google.api.HttpBody)
    returns (stream google.api.HttpBody);
}

使用這個類型只會改變要求和回應主體的處理方式,所有其他功能的運作方式皆維持不變。

欄位
content_type

string

表示主體內容類型的 HTTP Content-Type 字串。

data

bytes

HTTP 主體二進位檔資料。

extensions[]

Any

應用程式專屬回應中繼資料。必須在串流 API 的第一個回應中進行設定。