Skip to content

Commit

Permalink
feat: create backend endpoint (#15)
Browse files Browse the repository at this point in the history
* build: build a simple cmake project

* chore: add some .gitignore files

* docs: add README

* build: add Makefile with CMake commands

* chore: update .gitignore

* build: follow Conan 2.0 simple CMake project tutorial

* build: use conanfile.py instead of conanfile.txt

* docs: add conan command to README

* build: change c build to c++ build

* build: switch import from zlib to Crow

* docs: update README with correct cmake command

* feat: create hello world application

https://crowcpp.org/master/getting_started/your_first_application/

* docs: update set up instructions

* feat: add success response to endpoint

* docs: changes to readme

* docs: update README.md

---------

Co-authored-by: ni-jessica <[email protected]>
Co-authored-by: stellaljung <[email protected]>
  • Loading branch information
3 people authored Oct 18, 2023
1 parent f19306e commit ad53f73
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
2 changes: 2 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
CMakeUserPresets.json
7 changes: 7 additions & 0 deletions backend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.27)
project(backend)

find_package(Crow REQUIRED)

add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} Crow::Crow)
24 changes: 24 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Backend

## Configuration

In `/backend`, install conan:

```bash
brew install conan cmake
conan install . --output-folder=build --build=missing
```

Set up the `/build/` folder:

```bash
mkdir build && cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build .
```

From `/backend`, start the server:

```bash
cd build && ./backend
```
12 changes: 12 additions & 0 deletions backend/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from conan import ConanFile


class BackendRecipe(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeToolchain", "CMakeDeps"

def requirements(self):
self.requires("crowcpp-crow/1.0+5")

def build_requirements(self):
self.tool_requires("cmake/3.22.6")
20 changes: 20 additions & 0 deletions backend/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "crow.h"

int main(void) {
// delcare crow application
crow::SimpleApp app;

// define endpoint at the root directory
CROW_ROUTE(app, "/")([](){
crow::json::wvalue response;
response["status"] = "success";
return response;
});

// set the port, set the app to run on multiple threads, and run the app
app.port(18080).multithreaded().run();
}

0 comments on commit ad53f73

Please sign in to comment.