restinio::http_method_id_t Class Reference

A type for representation of HTTP method ID. More...

`#include <http_headers.hpp>`

## Public Member Functions

constexpr | http_method_id_t () noexcept
constexpr | http_method_id_t (int value, const char *name) noexcept
constexpr | http_method_id_t (const http_method_id_t &) noexcept=default
constexpr http_method_id_t & | operator= (const http_method_id_t &) noexcept=default
constexpr | http_method_id_t (http_method_id_t &&) noexcept=default
constexpr http_method_id_t & | operator= (http_method_id_t &&) noexcept=default
constexpr auto | raw_id () const noexcept
constexpr const char * | c_str () const noexcept

## Static Public Attributes

static constexpr const int | unknown_method = -1

## Private Attributes

int | m_value
const char * | m_name

## Friends

constexpr bool | operator== (const http_method_id_t &a, const http_method_id_t &b) noexcept
constexpr bool | operator!= (const http_method_id_t &a, const http_method_id_t &b) noexcept
constexpr bool | operator< (const http_method_id_t &a, const http_method_id_t &b) noexcept

## Detailed Description

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:

constexpr const restinio::http_method_id_t my_http_method(255, "MY-METHOD");
restinio::http_method_id_t
A type for representation of HTTP method ID.
Definition: http_headers.hpp:1744

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.

## Constructor & Destructor Documentation

## http_method_id_t() [1/4]

constexpr restinio::http_method_id_t::http_method_id_t | ( |  | ) |

inlineconstexprnoexcept

Definition at line 1751 of file http_headers.hpp.

## http_method_id_t() [2/4]

constexpr restinio::http_method_id_t::http_method_id_t | ( | int | value,
|  | const char * | name
| ) |  |

inlineconstexprnoexcept

Definition at line 1755 of file http_headers.hpp.

## http_method_id_t() [3/4]

constexpr restinio::http_method_id_t::http_method_id_t | ( | const http_method_id_t & |  | ) |

constexprdefaultnoexcept

## http_method_id_t() [4/4]

constexpr restinio::http_method_id_t::http_method_id_t | ( | http_method_id_t && |  | ) |

constexprdefaultnoexcept

## Member Function Documentation

## c_str()

constexpr const char * restinio::http_method_id_t::c_str | ( |  | ) | const

inlineconstexprnoexcept

Definition at line 1774 of file http_headers.hpp.

## operator=() [1/2]

constexpr http_method_id_t & restinio::http_method_id_t::operator= | ( | const http_method_id_t & |  | ) |

constexprdefaultnoexcept

## operator=() [2/2]

constexpr http_method_id_t & restinio::http_method_id_t::operator= | ( | http_method_id_t && |  | ) |

constexprdefaultnoexcept

## raw_id()

constexpr auto restinio::http_method_id_t::raw_id | ( |  | ) | const

inlineconstexprnoexcept

Definition at line 1771 of file http_headers.hpp.

## Friends And Related Function Documentation

## operator!=

constexpr bool operator!= | ( | const http_method_id_t & | a,
|  | const http_method_id_t & | b
| ) |  |

friend

Definition at line 1782 of file http_headers.hpp.

## operator<

constexpr bool operator< | ( | const http_method_id_t & | a,
|  | const http_method_id_t & | b
| ) |  |

friend

Definition at line 1786 of file http_headers.hpp.

## operator==

constexpr bool operator== | ( | const http_method_id_t & | a,
|  | const http_method_id_t & | b
| ) |  |

friend

Definition at line 1777 of file http_headers.hpp.

## Member Data Documentation

## m_name

const char* restinio::http_method_id_t::m_name

private

Definition at line 1746 of file http_headers.hpp.

## m_value

int restinio::http_method_id_t::m_value

private

Definition at line 1745 of file http_headers.hpp.

## unknown_method

constexpr const int restinio::http_method_id_t::unknown_method = -1

staticconstexpr

Definition at line 1749 of file http_headers.hpp.

The documentation for this class was generated from the following file:

- restinio/http_headers.hpp