Couchbase C Client
2.4.4
|
Schedule HTTP requests to the server.
This includes management and view requests
Functions | |
lcb_http_complete_callback | lcb_set_http_complete_callback (lcb_t, lcb_http_complete_callback) |
Set the HTTP completion callback for HTTP request completion. More... | |
lcb_http_data_callback | lcb_set_http_data_callback (lcb_t, lcb_http_data_callback) |
Set the HTTP data stream callback for streaming responses. More... | |
lcb_error_t | lcb_make_http_request (lcb_t instance, const void *command_cookie, lcb_http_type_t type, const lcb_http_cmd_t *cmd, lcb_http_request_t *request) |
Execute HTTP request matching given path and yield JSON result object. More... | |
void | lcb_cancel_http_request (lcb_t instance, lcb_http_request_t request) |
Cancel ongoing HTTP request. More... | |
Typedefs | |
typedef void(* | lcb_http_res_callback )(lcb_http_request_t request, lcb_t instance, const void *cookie, lcb_error_t error, const lcb_http_resp_t *resp) |
Callback invoked for HTTP requests. More... | |
typedef lcb_http_res_callback | lcb_http_data_callback |
typedef lcb_http_res_callback | lcb_http_complete_callback |
Enumerations | |
enum | lcb_http_type_t |
The type of HTTP request to execute. More... | |
enum | lcb_http_method_t |
HTTP Request method enumeration These just enumerate the various types of HTTP request methods supported. More... | |
lcb_http_complete_callback lcb_set_http_complete_callback | ( | lcb_t | , |
lcb_http_complete_callback | |||
) |
Set the HTTP completion callback for HTTP request completion.
This callback will be invoked once when the response is complete. If the lcb_HTTPCMDv0::chunked flag was set, the lcb_HTTRESPv0::bytes will be NULL
, otherwise it will contain the fully buffered response.
lcb_http_data_callback lcb_set_http_data_callback | ( | lcb_t | , |
lcb_http_data_callback | |||
) |
Set the HTTP data stream callback for streaming responses.
This callback is invoked only if the lcb_HTTPCMDv0::chunked flag is true. The lcb_HTTRESPv0::bytes field will on each invocation contain a new fragment of data which should be processed by the client. When the request is complete, the the callback specified by lcb_set_http_complete_callback() will be invoked with the lcb_HTTPRESPv0::bytes field set to NULL
lcb_error_t lcb_make_http_request | ( | lcb_t | instance, |
const void * | command_cookie, | ||
lcb_http_type_t | type, | ||
const lcb_http_cmd_t * | cmd, | ||
lcb_http_request_t * | request | ||
) |
Execute HTTP request matching given path and yield JSON result object.
Depending on type it could be:
LCB_HTTP_TYPE_VIEW
The client should setup view_complete callback in order to fetch the result. Also he can setup view_data callback to fetch response body in chunks as soon as possible, it will be called each time the library receive a data chunk from socket. The empty bytes
argument (NULL pointer and zero size) is the sign of end of response. Chunked callback allows to save memory on large datasets.
LCB_HTTP_TYPE_MANAGEMENT
Management requests allow you to configure the cluster, add/remove buckets, rebalance etc. The result will be passed to management callbacks (data/complete).
Fetch first 10 docs from _design/test/_view/all
view
The same as above but with POST filter
instance | The handle to lcb |
command_cookie | A cookie passed to all of the notifications from this command |
type | The type of the request needed. |
cmd | The struct describing the command options |
request | Where to store request handle |
void lcb_cancel_http_request | ( | lcb_t | instance, |
lcb_http_request_t | request | ||
) |
Cancel ongoing HTTP request.
This API will stop the current request. Any pending callbacks will not be invoked any any pending data will not be delivered. Useful for a long running request which is no longer needed
instance | The handle to lcb |
request | The request handle |
struct lcb_HTTPCMDv0 |
Structure for lcb_make_http_request()
Data Fields | ||
---|---|---|
const char * | path |
A view path string with optional query params (e.g. skip, limit etc.) |
lcb_SIZE | npath |
Length of the path. Mandatory |
const void * | body | The POST body for HTTP request. |
lcb_SIZE | nbody |
Length of the body. Mandatory if |
lcb_http_method_t | method | |
int | chunked | If true the client will use lcb_http_data_callback to notify about response and will call lcb_http_complete with empty data eventually. |
const char * | content_type |
The Content-Type header for request. For view requests it is usually |
struct lcb_HTTPCMDv1 |
v1 is used by the raw http requests.
It is exactly the same layout as v0, but it contains an extra field; the hostname & port to use....
Data Fields | ||
---|---|---|
const char * | path |
|
lcb_SIZE | npath | |
const void * | body |
|
lcb_SIZE | nbody | |
lcb_http_method_t | method | |
int | chunked | |
const char * | content_type | |
const char * | host | |
const char * | username | |
const char * | password |
struct lcb_http_cmd_t |
Wrapper structure for lcb_make_http_request.
Data Fields | ||
---|---|---|
int | version | |
union lcb_http_cmd_t | v |
struct lcb_HTTPRESPv0 |
Response structure received for HTTP requests.
The headers
field is a list of key-value headers for HTTP, so it may be traversed like so:
typedef void(* lcb_http_res_callback)(lcb_http_request_t request, lcb_t instance, const void *cookie, lcb_error_t error, const lcb_http_resp_t *resp) |
Callback invoked for HTTP requests.
request | Original request handle |
instance | The instance on which the request was issued |
cookie | Cookie associated with the request |
error | Error code for request. Note that more information may likely be found within the response structure itself, specifically the lcb_HTTPRESPv0::status and lcb_HTTPRESPv0::bytes field |
resp | The response structure |
enum lcb_http_type_t |
The type of HTTP request to execute.
Enumerator | |
---|---|
LCB_HTTP_TYPE_VIEW |
Execute a request against the bucket. The handle must be of LCB_TYPE_BUCKET and must be connected. |
LCB_HTTP_TYPE_MANAGEMENT |
Execute a management API request. The credentials used will match those passed during the instance creation time. Thus is the instance type is LCB_TYPE_BUCKET then only bucket-level credentials will be used. |
LCB_HTTP_TYPE_RAW |
Execute an arbitrary request against a host and port. |
enum lcb_http_method_t |
HTTP Request method enumeration These just enumerate the various types of HTTP request methods supported.
Refer to the specific cluster or view API to see which method is appropriate for your request