A type for representation of HTTP method ID.
RESTinio uses http_parser for working with HTTP-protocol. HTTP-methods in http_parser are identified by int
s like HTTP_GET, HTTP_POST and so on.
Usage of plain int
is error prone. So since v.0.5.0 RESTinio contain type http_method_id_t as type for ID of HTTP method.
An instance of http_method_id_t contains two values:
- integer identifier from http_parser (like HTTP_GET, HTTP_POST and so on);
- a string representation of HTTP method ID (like "GET", "POST", "DELETE" and so on).
There is an important requirement for user-defined HTTP method IDs: a pointer to string representation of HTTP method ID must outlive the instance of http_method_id_t. It means that is safe to use string literals or static strings, for example:
A type for representation of HTTP method ID.
- Note
- Instances of http_method_id_t can't be used in switch() operator. For example, you can't write that way:
const int method_id = ...;
switch(method_id) {
case restinio::http_method_get(): ...; break;
case restinio::http_method_post(): ...; break;
case restinio::http_method_delete(): ...; break;
}
In that case raw_id() method can be used: const int method_id = ...;
switch(method_id) {
case restinio::http_method_get().raw_id(): ...; break;
case restinio::http_method_post().raw_id(): ...; break;
case restinio::http_method_delete().raw_id(): ...; break;
}
- Since
- v.0.5.0
Definition at line 1743 of file http_headers.hpp.