AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::rest::Form Class Reference

#include <form.hpp>

Collaboration diagram for anch::rest::Form:

Public Member Functions

 Form ()
Form & add (std::string_view name, std::string value)
Form & addFile (std::string_view name, std::string_view filename, anch::codec::MediaType mediaType, std::string content)
Form & add (anch::rest::Part part)
bool has (std::string_view name) const noexcept
std::optional< std::string_view > field (std::string_view name) const
std::vector< std::string_view > fields (std::string_view name) const
const anch::rest::Part * part (std::string_view name) const noexcept
std::vector< const anch::rest::Part * > parts (std::string_view name) const
std::size_t size () const noexcept
bool empty () const noexcept
std::vector< anch::rest::Part >::const_iterator begin () const noexcept
std::vector< anch::rest::Part >::const_iterator end () const noexcept
const std::vector< anch::rest::Part > & getParts () const noexcept

Detailed Description

Form: ordered parts ( application/x-www-form-urlencoded or multipart/form-data bodies). A name can be repeated (arrays).

form.add("name", "Rex").add("tags", "dog").add("tags", "brown");
std::optional<std::string_view> name = form.field("name");
std::vector<std::string_view> tags = form.fields("tags");

Fields are converted on server side with formField<T>() and requiredFormField<T>() .

Author
Vincent Lachenal
Since
0.2

Constructor & Destructor Documentation

◆ Form()

anch::rest::Form::Form ( )

Form constructor

Member Function Documentation

◆ add() [1/2]

Form & anch::rest::Form::add ( anch::rest::Part part)

Add part

Parameters
partthe part
Returns
this
Here is the call graph for this function:

◆ add() [2/2]

Form & anch::rest::Form::add ( std::string_view name,
std::string value )

Add field

Parameters
namethe field name
valuethe field value
Returns
this
Here is the call graph for this function:

◆ addFile()

Form & anch::rest::Form::addFile ( std::string_view name,
std::string_view filename,
anch::codec::MediaType mediaType,
std::string content )

Add file

Parameters
namethe part name
filenamethe file name
mediaTypethe content media type
contentthe content
Returns
this
Here is the call graph for this function:

◆ begin()

std::vector< anch::rest::Part >::const_iterator anch::rest::Form::begin ( ) const
noexcept

Get parts begin iterator

Returns
the begin iterator
Here is the call graph for this function:

◆ empty()

bool anch::rest::Form::empty ( ) const
noexcept

Check if form is empty

Returns
true when form has no part
Here is the call graph for this function:

◆ end()

std::vector< anch::rest::Part >::const_iterator anch::rest::Form::end ( ) const
noexcept

Get parts end iterator

Returns
the end iterator
Here is the call graph for this function:

◆ field()

std::optional< std::string_view > anch::rest::Form::field ( std::string_view name) const

Get first part content

Parameters
namethe part name
Returns
the content, empty when there is no part with this name

◆ fields()

std::vector< std::string_view > anch::rest::Form::fields ( std::string_view name) const

Get every part content with name

Parameters
namethe part name
Returns
the contents, in order

◆ getParts()

const std::vector< anch::rest::Part > & anch::rest::Form::getParts ( ) const
noexcept

Get parts

Returns
the parts, in order
Here is the call graph for this function:

◆ has()

bool anch::rest::Form::has ( std::string_view name) const
noexcept

Check if form has a part

Parameters
namethe part name
Returns
true when form has a part with this name

◆ part()

const anch::rest::Part * anch::rest::Form::part ( std::string_view name) const
noexcept

Get first part

Parameters
namethe part name
Returns
the part, nullptr when there is no part with this name

◆ parts()

std::vector< const anch::rest::Part * > anch::rest::Form::parts ( std::string_view name) const

Get every part with name

Parameters
namethe part name
Returns
the parts, in order

◆ size()

std::size_t anch::rest::Form::size ( ) const
noexcept

Get number of parts

Returns
the number of parts

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