Controllers

A controller wires HTTP routes to the data layer. Each one extends Garvan::BaseContoller and exposes the five REST actions you'd expect.

BaseController

The base class declares a small contract:

class BaseContoller : public Helper
{
public:
    virtual json index() = 0;          // GET /resource
    json         create(json model);   // POST /resource
    json         read(string id);      // GET /resource/:id
    json         update(json model);   // PUT /resource/:id
    void         erease();             // DELETE /resource/:id
    json         getById(string id);
};

Only index() is pure-virtual — everything else has a default implementation you can override per resource.

REST actions

A typical resource controller:

// app/controllers/api/PostController.h
#pragma once
#include "controller/BaseContoller.h"
#include "../../services/PostService.h"

class PostController : public Garvan::BaseContoller
{
public:
    json index() override {
        PostService svc;
        return svc.index();
    }
};

Wire it into a route in routes/ApiRoutes.cpp:

CROW_ROUTE(app, "/api/posts")([] {
    PostController c;
    return jsonresponse{ c.index() };
});