Skip to content

Commit

Permalink
refactor: added macros for http verbs
Browse files Browse the repository at this point in the history
  • Loading branch information
araujo88 committed Apr 9, 2024
1 parent c93edd8 commit c66dd4f
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 13 deletions.
8 changes: 7 additions & 1 deletion include/server.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "router.hpp"
#include "context.hpp"
#include "router.hpp"
#include <boost/asio.hpp>
#include <boost/beast.hpp>
#include <boost/json.hpp>
Expand All @@ -16,6 +16,12 @@ namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = net::ip::tcp; // from <boost/asio/ip/tcp.hpp>

#define GET (http::verb::get)
#define POST (http::verb::post)
#define PUT (http::verb::put)
#define PATCH (http::verb::patch)
#define DELETE (http::verb::delete_)

class Server {
private:
short port;
Expand Down
22 changes: 10 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,21 @@ int main(void) {

router->setPrefix("/v1");

router->addRoute(http::verb::get, "/person", [personController](auto &ctx) {
router->addRoute(GET, "/person", [personController](auto &ctx) {
personController->getPersons(ctx);
});

router->addRoute(
http::verb::post, "/person",
[personController](auto &ctx) { personController->createPerson(ctx); });
router->addRoute(POST, "/person", [personController](auto &ctx) {
personController->createPerson(ctx);
});

router->addRoute(http::verb::get, "/person/{id}",
[personController](auto &ctx) {
personController->getPersonById(ctx);
});
router->addRoute(GET, "/person/{id}", [personController](auto &ctx) {
personController->getPersonById(ctx);
});

router->addRoute(http::verb::delete_, "/person/{id}",
[personController](auto &ctx) {
personController->deletePersonById(ctx);
});
router->addRoute(DELETE, "/person/{id}", [personController](auto &ctx) {
personController->deletePersonById(ctx);
});

std::cout << "Server starting on port " << server.getPort() << std::endl;
server.run();
Expand Down
129 changes: 129 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
Binary file not shown.

0 comments on commit c66dd4f

Please sign in to comment.