Design a Restful API that support One to Many Relation

28 views
Skip to first unread message

Henry Nguyen

unread,
May 25, 2018, 12:18:26 AM5/25/18
to ngrest

Hi NGREST GateKeeper

I have been designed my URI using a single entity users/{id} and messages/{id}

Can NGRest support users/{id}/messages{id}?

Thanks and Regards



namespace lxsextel {

//! Dummy description for the service
/*! Some detailed description of the service */
// '*location' comment sets resource path for this service
// *location: users
// *table: users
    struct User
    {
        // *pk: true
        // *autoincrement: true
        ngrest::Nullable<int> id;

        // *unique: true
        std::string username;

        std::string password;

        int userstate; // deleted, activated, deactivated

        std::string firstname;

        std::string lastname;

        std::string mi;

        std::string idcode;

        int companyid;

        std::string ssn;

        std::string photoidfilename;

        std::string email;

        std::string phone;

        int accesslevelid;

        std::string description;

    };

    class Users: public ngrest::Service
    {
    public:


        // *method: GET
        // *location: /
        std::list<User> list();



        // *method: POST
        // *location: /{id}
        int create(const User& user);



        // *method: GET
        // *location: /{id}
        User read(int id) const;



        // *method: PUT
        // *location: /{id}
        void update(int id, const User& user);



        // *method: DELETE
        // *location: /{id}
        void del(int id);
    };

}




Reply all
Reply to author
Forward
0 new messages