HTTP variable in path

kaspernyhus
Posts: 22
Joined: Tue Mar 01, 2022 7:38 am

HTTP variable in path

Postby kaspernyhus » Tue Jul 05, 2022 2:45 pm

Hi,

Is it possible to parse a variable in the URL path by the uri handler e.g.

POST someurl/control/23

Code: Select all

httpd_uri_t new_uri = {
	.uri = "/control/:ctl_id",
	.method = HTTP_POST,
	.handler = ctl_handler,
	.user_ctx = NULL
};
httpd_register_uri_handler(server, &new_uri);
and get ctl_id = 23

if that makes sense...

thanks

kaspernyhus
Posts: 22
Joined: Tue Mar 01, 2022 7:38 am

Re: HTTP variable in path

Postby kaspernyhus » Wed Jul 06, 2022 10:07 am

Found it!

Code: Select all

/* Use the URI wildcard matching function in order to
     * allow the same handler to respond to multiple different
     * target URIs which match the wildcard scheme */
    config.uri_match_fn = httpd_uri_match_wildcard;

Code: Select all

static const httpd_uri_t set_ml_cntl = {
    .uri       = "/api/v1/masterlink/control/*",
    .method    = HTTP_POST,
    .handler   = ml_cntl_set_handler,
    .user_ctx  = NULL
};

Who is online

Users browsing this forum: No registered users and 125 guests