Example of ngrest service with using the complex types
Dmitry edited this page Mar 28, 2016
·
1 revision
Create the service and name it Pets:
ngrest create Pets
cd pets
Edit generated sources (located in Pets/src
directory) like this:
Pets.h
#ifndef PETS_H
#define PETS_H
#include <ngrest/common/Service.h>
#include <string>
#include <list>
struct Pet
{
enum class Species
{
canine,
feline
};
Species species;
std::string name;
std::string birthday;
};
//! Pets service
/*! Example of using complex data types */
// *location: pets
class Pets: public ngrest::Service
{
public:
//! gets list of pets
std::list<Pet> getPets();
};
#endif // PETS_H
Pets.cpp
#include "Pets.h"
std::list<Pet> Pets::getPets()
{
return std::list<Pet>({
{
Pet::Species::canine,
"spot",
"Jan 1, 2010"
},
{
Pet::Species::feline,
"puff",
"July 4, 2014"
},
});
}
Start ngrest:
ngrest
The response from this service: