Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
orbit::testing::Client Class Reference

Calls an application's routes in-process, without listen() or sockets: for fast, port-free tests. More...

#include <Client.hpp>

Collaboration diagram for orbit::testing::Client:

Public Member Functions

 Client (server::App &app, size_t worker_threads=2)
 
 Client (const routing::Router &router, size_t worker_threads=2)
 
 ~Client ()
 
 Client (const Client &)=delete
 
Client & operator= (const Client &)=delete
 
RequestBuilder get (std::string target)
 
RequestBuilder post (std::string target)
 
RequestBuilder put (std::string target)
 
RequestBuilder patch (std::string target)
 
RequestBuilder del (std::string target)
 
RequestBuilder options (std::string target)
 
RequestBuilder head (std::string target)
 
RequestBuilder request (http::HttpMethod method, std::string target)
 
std::map< std::string, std::string > & cookies ()
 The cookie jar: name -> value, updated from every response.
 

Private Attributes

const routing::Router & router_
 
std::unique_ptr< Runtime > runtime_
 
std::map< std::string, std::string > cookies_
 

Friends

class RequestBuilder
 

Detailed Description

Calls an application's routes in-process, without listen() or sockets: for fast, port-free tests.

Requests go through the same router as on the network: global, prefix and group middleware, routing (404/405), error handlers, sessions. Responses are collected in memory, chunks and SSE events included. Coroutine handlers work: the client runs a small thread pool and event loop of its own (ResponseWriter::thread_pool() / proactor()) and waits for the response.

app.post("/tasks", create_task);
auto res = client.post("/tasks").json({{"title", "x"}}).send();
EXPECT_EQ(res.status, 201);
The main application class for the Orbit Framework.
Definition App.hpp:36
App & post(const std::string &path, routing::RouteHandler handler)
Registers a POST route.
Calls an application's routes in-process, without listen() or sockets: for fast, port-free tests.
Definition Client.hpp:105
Definition Config.hpp:30

The client keeps a cookie jar: cookies the application sets are sent with later requests, so a login followed by an authenticated request works. What the network layer adds (Date, Content-Length framing, compression of the wire format) is not applied.

Constructor & Destructor Documentation

◆ Client() [1/3]

orbit::testing::Client::Client ( server::App &  app,
size_t  worker_threads = 2 
)
explicit

◆ Client() [2/3]

orbit::testing::Client::Client ( const routing::Router &  router,
size_t  worker_threads = 2 
)
explicit

◆ ~Client()

orbit::testing::Client::~Client ( )

◆ Client() [3/3]

orbit::testing::Client::Client ( const Client &  )
delete

Member Function Documentation

◆ cookies()

std::map< std::string, std::string > & orbit::testing::Client::cookies ( )
inline

The cookie jar: name -> value, updated from every response.

◆ del()

RequestBuilder orbit::testing::Client::del ( std::string  target)

◆ get()

RequestBuilder orbit::testing::Client::get ( std::string  target)
inline

◆ head()

RequestBuilder orbit::testing::Client::head ( std::string  target)
inline

◆ operator=()

Client & orbit::testing::Client::operator= ( const Client &  )
delete

◆ options()

RequestBuilder orbit::testing::Client::options ( std::string  target)
inline

◆ patch()

RequestBuilder orbit::testing::Client::patch ( std::string  target)
inline

◆ post()

RequestBuilder orbit::testing::Client::post ( std::string  target)
inline

◆ put()

RequestBuilder orbit::testing::Client::put ( std::string  target)
inline

◆ request()

RequestBuilder orbit::testing::Client::request ( http::HttpMethod  method,
std::string  target 
)
inline

Friends And Related Symbol Documentation

◆ RequestBuilder

friend class RequestBuilder
friend

Member Data Documentation

◆ cookies_

std::map<std::string, std::string> orbit::testing::Client::cookies_
private

◆ router_

const routing::Router& orbit::testing::Client::router_
private

◆ runtime_

std::unique_ptr<Runtime> orbit::testing::Client::runtime_
private

The documentation for this class was generated from the following file: