AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::rest::FormMapper< T > Struct Template Reference
Collaboration diagram for anch::rest::FormMapper< T >:

Detailed Description

template<typename T>
struct anch::rest::FormMapper< T >

Mapping between T and Form , used by FormUrlEncoded and Multipart codecs to read and write T bodies. Specializations define:

  • static void toForm(const T& value, anch::rest::Form& form, anch::codec::Side side)
  • static void fromForm(T& value, const anch::rest::Form& form, anch::codec::Side side) : errors are reported with exceptions ( 400 on server side)
template<>
struct anch::rest::FormMapper<UploadPhoto> {
static void toForm(const UploadPhoto& value, anch::rest::Form& form, anch::codec::Side) {
anch::rest::addFormField(form, "description", value.description);
anch::rest::addFormFile(form, "photo", value.photo); // anch::rest::Part
}
static void fromForm(UploadPhoto& value, const anch::rest::Form& form, anch::codec::Side side) {
value.description = anch::rest::requiredFormField<std::string>(form, "description");
value.photo = anch::rest::requiredFormFile(form, "photo");
}
};
api.post("/pets/{id}/photo", [](uint64_t id, anch::rest::Body<UploadPhoto> upload) { return savePhoto(id, &upload->photo); })
.consumes<anch::rest::Multipart>();
Template Parameters
Tthe mapped type
Since
0.2

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