dragonfly/src/server/http_api.h
Roman Gershman 966d7f55ba
chore: preparation for basic http api (#2764)
* chore: preparation for basic http api

The goal is to provide very basic support for simple commands,
fancy stuff like pipelining, blocking commands won't work.

1. Added optional registration for /api handler.
2. Implemented parsing of post body.
3. Added basic formatting routine for the response. It does not cover all the commands but should suffice for
   basic usage.

The API is a POST method and the body of the request should contain command arguments formatted as json array.
For example, `'["set", "foo", "bar", "ex", "100"]'`.
The response is a json object with either `result` field holding the response of the command or
`error` field containing the error message sent by the server.
See `test_http` test in tests/dragonfly/connection_test.py for more details.


* chore: cover iouring with enable_direct_fd

---------

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-03-25 12:12:31 +02:00

26 lines
940 B
C++

// Copyright 2024, DragonflyDB authors. All rights reserved.
// See LICENSE for licensing terms.
//
#pragma once
#include "util/http/http_handler.h"
namespace dfly {
class Service;
using HttpRequest = util::HttpListenerBase::RequestType;
/**
* @brief The main handler function for dispatching commands via HTTP.
*
* @param args - query arguments. currently not used.
* @param req - full http request including the body that should consist of a json array
* representing a Dragonfly command. aka `["set", "foo", "bar"]`
* @param service - a pointer to dfly::Service* object.
* @param http_cntxt - a pointer to the http context object which provide dragonfly context
* information via user_data() and allows to reply with HTTP responses.
*/
void HttpAPI(const util::http::QueryArgs& args, HttpRequest&& req, Service* service,
util::HttpContext* http_cntxt);
} // namespace dfly