Request APIs
ys_request*
A ys_request* contains request data such as the path, method, body, route and query parameters, etc.
ys_req_get_parameter
char* ys_req_get_parameter(ys_request* req, const char* key);ys_req_get_parameter returns the parameter value matching key, or NULL if not extant. By parameter, we mean a route match value.
For example, the following route
ys_router_register(router, "/:key[^\\d+$]", handler, YS_METHOD_GET);will match any digit after /. For a request /10, the resulting ys_request* will contain the parameter key=10. Thus, ys_req_get_parameter(req, "key"); will yield "10".
ys_req_num_parameters
unsigned int ys_req_num_parameters(ys_request *req);ys_req_num_parameters returns the number of parameters matched on the given request. For example, given the route
ys_router_register(router, "/:key[^\\d+$]/:fruit[(.+)]", handler, YS_METHOD_GET);and a request
/12/bananays_req_num_parameters will return 2.
ys_req_has_parameters
bool ys_req_has_parameters(ys_request *req);ys_req_has_parameters returns a bool indicating whether the given request contains any matched parameters.
ys_req_get_query
char **ys_req_get_query(ys_request *req, const char *key);ys_req_get_query returns a char* array of all values corresponding to a given URL query key. For example, if the request URL was /some-url/?num=1&num=2&num=3, ys_req_get_query(req, "num") will return ["1", "2", "3"].
Use ys_req_num_queries to determine the size of this list.
ys_req_has_query
bool ys_req_has_query(ys_request *req, const char *key);ys_req_has_query returns a bool indicating whether the request contains a query match for key.
ys_req_num_queries
unsigned int ys_req_num_queries(ys_request *req, const char *key);ys_req_num_queries returns the number of values associated with a given query key key.
ys_req_get_path
char *ys_req_get_path(ys_request *req);ys_req_get_path returns the full request path.
ys_req_get_route_path
char *ys_req_get_route_path(ys_request *req);ys_req_get_route_path returns the request path segment that was matched on the router. For sub-routers, this will be the sub-path. For example,
path = /api/demo
route_path = /demoys_req_get_method
char *ys_req_get_method(ys_request *req);ys_req_get_method returns the request method.
ys_req_get_body
char *ys_req_get_body(ys_request *req);ys_req_get_body returns the full request body.
ys_req_get_raw
char *ys_req_get_raw(ys_request *req);ys_req_get_raw returns the entire, raw request as it was received by the server.
ys_req_get_version
char *ys_req_get_version(ys_request *req);ys_req_get_version returns the protocol version string included in the request.
ys_req_get_header
char *ys_req_get_header(ys_request *req, const char *key);ys_req_get_header retrieves the first value for a given header key on the request or NULL if not found.