Skip to content

jhammond/botz

Repository files navigation

botz - tiny RESTful status module for libev based daemons.

int main(int argc, char *argv[])
{
  struct botz_listen bl;
  struct evx_listen *el;

  int up = 1;
  unsigned long nr_clients = 1000000;

  struct json status_json[] = {
    J_OBJECT,
    J_PAIR("name", string, V, "tiny_botzd"),
    J_PAIR("up", bool, P, &up),
    J_PAIR("nr_clients", ulong, P, &nr_clients),
    J_END,
  };

  if (botz_listen_init(&bl, 64) < 0)
    FATAL("cannot initialize listener: %s\n", strerror(errno));

  if (botz_set_json(&bl, "/status", status_json, NULL) < 0)
    FATAL("cannot set resource `/status': %s\n", strerror(errno));

  el = &bl.bl_listen;

  if (evx_listen_bind_name(el, "localhost", "9901", 0, 128) < 0)
    FATAL("cannot bind to interface `localhost', service `9901': %s\n",
          strerror(errno));

  evx_listen_start(EV_DEFAULT_ el);

  ev_run(EV_DEFAULT_ 0);

  return 0;
}

$ curl http://localhost:9901/status
{"name":"tiny_botzd","up":true,"nr_clients":1000000}

About

tiny RESTful status module for libev based daemons

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published