Implementation:Tensorflow Serving HTTPServer
| Knowledge Sources | |
|---|---|
| Domains | HTTP, Factory |
| Last Updated | 2026-02-13 00:00 GMT |
Overview
A factory function that creates a libevent-based HTTP server instance, serving as the public entry point for obtaining an HTTPServerInterface implementation.
Description
The CreateEvHTTPServer() function is an inline factory that constructs an EvHTTPServer from the provided ServerOptions, calls Initialize() on it, and returns it as a unique_ptr to HTTPServerInterface. If initialization fails, it returns nullptr. This function is the only public mechanism for creating the libevent-based HTTP server, encapsulating the concrete implementation behind the abstract interface. Callers must call WaitForTermination() or WaitForTerminationWithTimeout() before the server object is destructed.
Usage
Use this as the entry point to create an HTTP server for the TensorFlow Serving REST API. Configure ServerOptions with ports and an executor, then call this factory to obtain a server instance.
Code Reference
Source Location
- Repository: Tensorflow_Serving
- File:
tensorflow_serving/util/net_http/server/public/httpserver.h - Lines: 1-52
Signature
inline std::unique_ptr<HTTPServerInterface> CreateEvHTTPServer(
std::unique_ptr<ServerOptions> options);
Import
#include "tensorflow_serving/util/net_http/server/public/httpserver.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| options | std::unique_ptr<ServerOptions> |
Yes | Configuration for the server including ports and executor |
Outputs
| Name | Type | Description |
|---|---|---|
| return | std::unique_ptr<HTTPServerInterface> |
The created server, or nullptr on initialization failure |
Usage Examples
Creating a Server
auto options = std::make_unique<ServerOptions>();
options->AddPort(8501);
options->SetExecutor(std::make_unique<MyExecutor>());
auto server = CreateEvHTTPServer(std::move(options));
if (server == nullptr) {
LOG(ERROR) << "Failed to create HTTP server";
return;
}
server->RegisterRequestHandler("/health", handler, RequestHandlerOptions());
server->StartAcceptingRequests();