Motion Master 6.0.0-alpha.86
Next-generation motion control software
Loading...
Searching...
No Matches
web_api.h File Reference
#include <uwebsockets/App.h>
#include <chrono>
#include <functional>
#include <nlohmann/json.hpp>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include "api/router.h"
Include dependency graph for web_api.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mm::api::RouteContext
 The live collaborators a route plug-in needs, handed to it at registration time. More...
 

Namespaces

namespace  mm
 
namespace  mm::node
 
namespace  mm::api
 HTTP-transport glue shared by the built-in server and route plug-in libs.
 

Typedefs

using mm::api::RegisterRoutesFn = std::function< void(Router &router, const RouteContext &ctx)>
 A route plug-in: registers its routes on the HTTP app.
 

Functions

template<typename Res >
Res * mm::api::setCorsOrigin (Res *res, std::string_view corsOrigin)
 Writes the Access-Control-Allow-Origin header and returns res for chaining.
 
template<typename Res >
Res * mm::api::setWireTime (Res *res, std::chrono::microseconds wireUs)
 Attaches the server-measured wire-time header (X-Wire-Us, microseconds) to a response.
 
template<typename Res >
void mm::api::sendJson (Res *res, std::string_view corsOrigin, const nlohmann::json &body)
 Writes body as a 200 application/json response with the CORS header.
 
template<typename Res >
void mm::api::sendBytes (Res *res, std::string_view corsOrigin, std::string_view contentType, std::string_view body)
 Writes body verbatim as a 200 response with the given contentType and the CORS header.
 
template<typename Res >
void mm::api::sendError (Res *res, std::string_view status, std::string_view corsOrigin, std::string_view message, std::optional< std::chrono::microseconds > wireUs=std::nullopt)
 Writes a status response carrying a {"error": message} JSON body and the CORS header.
 
template<typename Res >
void mm::api::sendStatus (Res *res, std::string_view status, std::string_view corsOrigin, std::optional< std::chrono::microseconds > wireUs=std::nullopt)
 Writes a bare status response (no body) with the CORS header.