TensorFlow Serving C++ API Documentation
http_rest_api_util.h
1 /* Copyright 2020 Google Inc. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7  http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef THIRD_PARTY_TENSORFLOW_SERVING_MODEL_SERVERS_HTTP_REST_API_UTIL_H_
17 #define THIRD_PARTY_TENSORFLOW_SERVING_MODEL_SERVERS_HTTP_REST_API_UTIL_H_
18 
19 #include <string>
20 #include <vector>
21 
22 #include "absl/strings/string_view.h"
23 #include "absl/types/optional.h"
24 #include "re2/re2.h"
25 #include "tensorflow/core/lib/core/status.h"
26 #include "tensorflow_serving/apis/get_model_metadata.pb.h"
27 #include "tensorflow_serving/apis/get_model_status.pb.h"
28 #include "tensorflow_serving/apis/model.pb.h"
29 
30 namespace tensorflow {
31 namespace serving {
32 
33 const char* const kHTTPRestApiHandlerPathRegex = "(?i)/v1/.*";
34 
35 void AddHeaders(std::vector<std::pair<string, string>>* headers);
36 
37 void AddCORSHeaders(std::vector<std::pair<string, string>>* headers);
38 
39 Status FillModelSpecWithNameVersionAndLabel(
40  const absl::string_view model_name,
41  const absl::optional<int64_t>& model_version,
42  const absl::optional<absl::string_view> model_version_label,
43  ::tensorflow::serving::ModelSpec* model_spec);
44 
45 // Parse model information from the request.
46 Status ParseModelInfo(const absl::string_view http_method,
47  const absl::string_view request_path, string* model_name,
48  absl::optional<int64_t>* model_version,
49  absl::optional<string>* model_version_label,
50  string* method, string* model_subresource,
51  bool* parse_successful);
52 
53 Status ToJsonString(const GetModelStatusResponse& response, string* output);
54 
55 Status ToJsonString(const GetModelMetadataResponse& response, string* output);
56 
57 } // namespace serving
58 } // namespace tensorflow
59 
60 #endif // THIRD_PARTY_TENSORFLOW_SERVING_MODEL_SERVERS_HTTP_REST_API_UTIL_H_