TensorFlow Serving C++ API Documentation
http_rest_api_handler_base.h
1 /* Copyright 2022 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 TENSORFLOW_SERVING_MODEL_SERVERS_HTTP_REST_API_HANDLER_BASE_H_
17 #define TENSORFLOW_SERVING_MODEL_SERVERS_HTTP_REST_API_HANDLER_BASE_H_
18 
19 #include <memory>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 #include "absl/strings/string_view.h"
25 #include "tensorflow/core/lib/core/status.h"
26 
27 namespace tensorflow {
28 namespace serving {
29 
30 // Base class of HttpRestApiHandler classes that handles HTTP/REST APIs of TF
31 // serving.
32 //
33 // Currently supported APIs are as follows:
34 //
35 // o Inference - Classify/Regress/Predict
36 //
37 // POST /v1/models/<model_name>:(classify|regress)
38 // POST /v1/models/<model_name>/versions/<ver>:(classify|regress)
39 //
40 // o Model status
41 //
42 // GET /v1/models/<model_name> (status of all versions)
43 // GET /v1/models/<model_name>/versions/<ver> (status of specific version)
44 //
45 // The API is documented here:
46 // tensorflow_serving/g3doc/api_rest.md
47 //
48 // Users of this class should typically create one instance of it at process
49 // startup, register paths defined by kPathRegex with the in-process HTTP
50 // server, and when a request arrives, forward the request to ProcessRequest()
51 // method.
52 //
53 // This class is thread safe.
55  public:
56  virtual ~HttpRestApiHandlerBase() = default;
57 
58  // Process a HTTP request.
59  //
60  // In case of errors, the `headers` and `output` are still relevant as they
61  // contain detailed error messages, that can be relayed back to the client.
62  virtual Status ProcessRequest(const absl::string_view http_method,
63  const absl::string_view request_path,
64  const absl::string_view request_body,
65  std::vector<std::pair<string, string>>* headers,
66  string* model_name, string* method,
67  string* output) = 0;
68 };
69 
70 } // namespace serving
71 } // namespace tensorflow
72 
73 #endif // TENSORFLOW_SERVING_MODEL_SERVERS_HTTP_REST_API_HANDLER_BASE_H_