CppRestAPI Tutorial 1
Share
Start the CppRest API tutorial.
Let's explain using the UsersAPI as an example.
At first
/CppRestApi/data/sql/get_users.sql
/CppRestApi/data/sql/insert_user.sql
/CppRestApi/data/sql/update_user.sql
/CppRestApi/data/sql/delete_user.sql
Next, implement the UserFormat class.
/CppRestApi/include/database/format/user_format.hpp
struct UserFormat
{
//Define the data format, Format::Record, in the Format structure.
struct Record
{
//Record structure corresponds to the database schema as a tuple type
Defined in Record::Columns.
using Columns = typename std :: tuple < unsigned int , std :: string , std :: string , unsigned int , std :: string >;
Columns record;
unsigned int id;
std ::string name;
std ::string password;
unsigned int auth_id;
std ::string token;
:: web :: json ::valuejson;
//In the Record constructor, set each member based on Record::Columns. Use this when creating a Record from a tuple type, such as when converting a database row to a Record.
Record ( Columns record ) : record {record} ;
//The json::value constructor is used when the UserAPI creates a record from the request body.
Record (:: web :: json :: value json ) : json {json}
}
Next time, we will implement the server API in /CppRestCpp/include/web.