Skip to content

Simple C++ application that interacts with different open api's to create text that you can receive on GET endpoints.

License

Notifications You must be signed in to change notification settings

dllg/cpp-funny-endpoints

Repository files navigation

CI

cpp-funny-endpoints

Simple C++ application that interacts with different open api's to create text that you can receive on GET endpoints. See swagger.yml

Uses vcpkg to handle dependencies and cmake build system. It uses nlohmann_json for json, drogon for http server part, cpr for http client part, spdlog for logging and gtest for testing.

Testing

Testing is done using gtest. Testing of the classes Funny and Service are done using dependency injection. Mocking of the client and server classes are done using googlemock.

Building locally

1. Setup dependencies using vcpkg

$ git clone ssh://[email protected]/microsoft/vcpkg
$ cd vcpkg
$ ./bootstrap-vcpkg.sh
  • Install dependencies
$ ./vcpkg install nlohmann_json gtest spdlog drogon cpp-httplib
  • set VCPKG_ROOT environment variable
$ export VCPKG_ROOT=/path/to/vcpkg

Create a build directory if you haven't already and initailize the dependencies:

mkdir build
cd build
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Debug
cd ..

2. Building

cmake --build build

3. Running

./build/bin/funny

4. Running the tests

The tests are automatically run after each build. You can run them by invoking:

./build/bin/funnytests

Building for docker

1. Building the image

docker-compose build

2. Running the container

docker-compose up -d

3. Running the tests

The tests are also run after building in docker. To run the tests in docker invoke:

docker run cpp-funny-endpoints funnytests

Running in kubernetes

See k8s/README.md.

Examples of using it

Get an advice

$ curl http://localhost:5000/v1/advice
{"message":"If you don't want something to be public, don't post it on the Internet."}

Get a Chuck Norris Joke

$ curl http://localhost:5000/v1/chucknorris
{"message":"there is no use crying over spilled milk, unless its Chuck Norris' milk because then your gonna die"}

Get a dad joke

$ curl http://localhost:5000/v1/dadjoke
{"message":"What do you call an eagle who can play the piano? Talonted!"}

Get a random message

$ curl http://localhost:5000/v1/random
{"message":"Advice: When painting a room, preparation is key. The actual painting should account for about 40% of the work."}

About

Simple C++ application that interacts with different open api's to create text that you can receive on GET endpoints.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published