Code Monkey home page Code Monkey logo

http-rest-api's Introduction

HTTP REST API in C++

Dependencies:

  • g++ 7.5
  • cmake 3.15+
  • vcpkg
  • POCO libraries
  • prometheus-cpp

How to use

Easiest way is to build it using build_dockerfile.sh and then running docker-compose up. If you do initiate the build without the script then do reference the proper image name in the docker-compose file.


Services:

  • Postgres
  • Adminer
  • Prometheus
  • Traefik
  • Grafana
  • This api via the image you built
    • API exposes stats on base path /
    • Test endpoints

test endpoints

This API is an example (or template), thus it only has one insert item and one get all items endpoints as a showcase or "how to".

  • [GET] / will expose server stats in json format
  • [GET] get/items
  • [POST] /item
    • content type application/json with payload, for simplicity and consistency the price is submitted as a string (example)
                    {
                        "name":"foo",
                        "price": "3.20",
                        "data":{
                            "something":{
                                "else":"here"
                            }
                        }
                    }

The service can be easily extended by defining handler functions in router file and then registering them with the mux map in Router class.

Prometheus

This setup already scrapes API and Traefik, check it here http://localhost:9007/graph. Traefik heap graph

Endpoint for checking discovered targets (Traefik and API should be there) http://localhost:9007/api/v1/targets.

Grafana

Grafana default credentials are admin/admin. This dashboard is added as a convenience for visualizations of data from PostgreSQL and Prometheus. The above databases can be added easily as sources, reference the host as the service name:

  • Postgres is db:5432
  • Prometheus is prometheus:9090

Traefik dashboard

Can be accessed locally here http://localhost:9009/dashboard/#/.

Alternative

Make sure you have the g++ compiler and CMake available through PATH. Run ./vcpkg_install.sh to pull in vcpkg and Poco (this builds the libraries).

Run build.sh and you should have a main binary produced.

Start the server ./main.

Tests

Make sure the test target is built. Run the available tests using ./build/test -v high -s. Make sure the server is running since it includes e2e.

http-rest-api's People

Contributors

wolvenspirit avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.