commit 80fc8ec6cb53ea8300281b00c5cbfe0d5e7346da Author: Tyler Perkins Date: Thu Apr 28 16:48:15 2022 -0400 Initial Commit; Initial Documentation diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..e4febf2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +#ignore all .o files +src/**/*.o + +#ignore all swp files +**/*.swp + +#ignore all executables, but still keep the bin folder +bin/* +!bin/.gitkeep diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md new file mode 100644 index 0000000..134107c --- /dev/null +++ b/DOCUMENTATION.md @@ -0,0 +1,82 @@ +DOCUMENATION +============ + +The following is the listing of all supported routes and methods by the API. +The API is broken down into the different actions + +Custom headers +-------------- + +When submitting a GET request to the `/proc` endpoints, +you can specify the `Accept:` header and choose +exactly what format you would like back. The API accepts the following mime +types + +* `application/json` + * *Default response* + * Returns as a json dictionary with sensible keys +* `text/plain` + * Returns exact response from the `/proc` file system + * For more about the format of these responses, refer to the proc(5) manpage + +Proc file responses +============ + +[GET] /proc/uptime +------------- + +* returns uptime and idle time +* Same as /proc/uptime + +Sample response + +``` +{ + "uptime": 72583.24 + "idle" : 834157.72 +} +``` + +[GET] /proc/meminfo +------------------- + +* returns infomration regarding system memory +* Same as /proc/meminfo + +Special formatted responses +=========================== + +[GET] /load +---------- + +* Returns load average over the past 1, 5, and 10 mins +* formatted version of /proc/loadavg + +Sample response + +``` +{ + "1" : 0.56 + "5" : 0.69 + "10" : 1.30 +} +``` + +[GET] /mem +---------- + +* returns memory usage +* formatted version of /proc/meminfo +* All responses are in kB + +Sample response + +``` +{ + "memtotal" : 16255116, + "memfree" : 2127320, + "memavailable" : 12324924, + "swaptotal" : 0, + "swapfree" : 0, +} +``` diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f86c14c --- /dev/null +++ b/Makefile @@ -0,0 +1,46 @@ +############################################################################### +# Tyler Perkins +# 9-23-21 +# Makefile +# + +CC = g++ + +FLAGS = -pipe + +CFLAGS = -Wall +CFLAGS += -Ofast +CFLAGS += -g +#CFLAGS += -pg + +LIBRARIES = -lpthread + +SRC = $(shell find ./src -name '*.cpp') +OBJ = $(subst .cpp,.o,$(SRC)) +BIN = ./bin + +PREFIX = /usr/local +MANPREFIX = $(PREFIX)/share/man + +TARGET = crowtest + +MAKEFLAGS += --jobs=4 + +OPTIONS = -DCROW_ENABLE_COMPRESSION -lz +#OPTIONS += -DCROW_ENABLE_SSL -lssl + +all : $(OBJ) + @echo LD $@ + @$(CC) $(FLAGS) $(CFLAGS) -o $(BIN)/$(TARGET) $(OBJ) $(LIBRARIES) $(OPTIONS) + +.cpp.o : + @echo CC $< + @$(CC) $(FLAGS) $(CFLAGS) $(LIBRARIES) $(OPTIONS) $(DEFINITIONS) -c $< -o $@ + +install : all + +uninstall : + +clean : + find . -type f -name '*.o' -delete + rm -rf $(BIN)/* diff --git a/README.md b/README.md new file mode 100644 index 0000000..f8cb75e --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +Learn crow +========== + +Learning the crow web framework diff --git a/bin/.gitkeep b/bin/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..0c144f6 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,23 @@ +/////////////////////////////////////////////////////////////////////////////// +// Tyler Perkins +// 28-4-22 +// Entry point +// + +#include +#include + +int main(int argc, char** argv){ + crow::SimpleApp app; + CROW_ROUTE(app, "/")([](){ + return "Hello World"; + }); + + CROW_ROUTE(app, "/json")([]{ + crow::json::wvalue response({{ "message", "Hello world" }}); + response["kek"] = "nay, cringe"; + return response; + }); + + app.port(5000).run(); +} diff --git a/src/routes.cpp b/src/routes.cpp new file mode 100644 index 0000000..e69de29