{"id":27219806,"url":"https://github.com/gotz1480/teapot","last_synced_at":"2025-04-10T06:05:27.934Z","repository":{"id":125834481,"uuid":"574766408","full_name":"gotz1480/teapot","owner":"gotz1480","description":"A simple and lightweight asynchronous web framework in C++","archived":false,"fork":false,"pushed_at":"2024-03-29T03:50:32.000Z","size":1677,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-04T13:13:20.495Z","etag":null,"topics":["cpp-library","cpp-network","cpp-web-services","web-framework","webframewok","webframework"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gotz1480.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-06T02:52:56.000Z","updated_at":"2025-01-18T21:18:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"2fb8f5ce-7fd1-4a50-a00a-bc20ae66249a","html_url":"https://github.com/gotz1480/teapot","commit_stats":null,"previous_names":["gotz1480/teapot"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotz1480%2Fteapot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotz1480%2Fteapot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotz1480%2Fteapot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotz1480%2Fteapot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gotz1480","download_url":"https://codeload.github.com/gotz1480/teapot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248166931,"owners_count":21058481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp-library","cpp-network","cpp-web-services","web-framework","webframewok","webframework"],"created_at":"2025-04-10T06:04:19.677Z","updated_at":"2025-04-10T06:05:27.893Z","avatar_url":"https://github.com/gotz1480.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# teapot 🫖\n\n[![license](https://img.shields.io/badge/license-GPL-green)](https://raw.githubusercontent.com/araujo88/teapot/main/LICENSE)\n[![build](https://github.com/araujo88/teapot/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/araujo88/teapot/actions/workflows/build.yml)\n\nA simple and lightweight asynchronous web framework in C++ that serves static websites.\n\n## Getting started\n\n### Pre-requisites\n\nThis library uses features from C++20.\n\n#### Linux\n\n- gcc\n- make\n\n#### Windows\n\n- Visual Studio 2022\n\n### Compiling\n\n`make clean \u0026\u0026 make`\n\n### Setting up\n\nIn `main.cpp` file:\n\n```cpp\n#include \"../include/teapot.hpp\"\n\nint main(int argc, char *argv[])\n{\n    tpt::Teapot server;\n    server.run();\n    return 0;\n}\n```\n\nTo start the server, run `./teapot`. This will start the server at the default url `localhost:8000`.\n\nTo run in a different port:\n\n```cpp\n#include \"../include/teapot.hpp\"\n\nint main(int argc, char *argv[])\n{\n    tpt::Teapot server = tpt::Teapot(atoi(argv[1]));\n    server.run();\n    return 0;\n}\n\n```\n\nStart the server by running `./teapot \u003cport_number\u003e`.\n\nOptionally, the following arguments can be provided for the server instance:\n\n```cpp\n#include \"../include/teapot.hpp\"\n\nint main(int argc, char *argv[])\n{\n    tpt::Teapot server = tpt::Teapot(ip_address, port, max_connections, logging_type, static_files_dir);\n    server.run();\n    return 0;\n}\n\n```\n\n`ip_address`: the server IP address. The default is `127.0.0.1`. \u003cbr\u003e\n`port`: the server port. The default is `8000`. \u003cbr\u003e\n`max_connections`: the maximum number of simultaneous requests. The default is `10`. \u003cbr\u003e\n`logging_type`: the Teapot server provides three levels of logging: `DEFAULT`, `DISABLED` and `VERBOSE`. \u003cbr\u003e\n`static_files_dir`: the relative folder path where static files are located. The default is set to `static`. \u003cbr\u003e\n\n## Serving files\n\nYou can link a HTML file to a URL by using the method `serveFile(url, file_path)`:\n\n```cpp\n#include \"../include/teapot.hpp\"\n\nint main(int argc, char *argv[])\n{\n    tpt::Teapot server;\n    server.serveFile(\"/example\", \"/example.html\");\n    server.run();\n    return 0;\n}\n```\n\n## Returning JSON responses\n\n```cpp\n#include \"../include/teapot.hpp\"\n\nint main(int argc, char *argv[])\n{\n    tpt::Teapot server;\n    server.returnJSON(\"/test\", \"{\\\"name\\\": \\\"john\\\", \\\"surname\\\": \\\"doe\\\"}\");\n    server.run();\n    return 0;\n}\n```\n\n## Returning hard-coded HTML\n\n```cpp\n#include \"../include/teapot.hpp\"\n\nint main(int argc, char *argv[])\n{\n    tpt::Teapot server;\n    server.returnHTML(\"/example\", \"\u003chtml\u003e\u003ch1\u003eExample\u003c/h1\u003e\u003c/html\u003e\");\n    server.run();\n    return 0;\n}\n```\n\n## Adding middleware\n\nTeapot web framework provides some builtin middleware such as CORS middleware, sanitizer and security headers by default. However, they can be customized to your needs by instantiating an object and then adding it to the server instance.\n\n```cpp\n#include \"../include/teapot.hpp\"\n#include \"../include/cors_middleware.hpp\"\n\nint main(int argc, char *argv[])\n{\n    tpt::Teapot server;\n    tpt::CORSMiddleware cors_middleware = tpt::CORSMiddleware(\"*\", \"*\", \"*\", 86400, true);\n    server.addMiddleware(cors_middleware);\n    server.run();\n    return 0;\n}\n```\n\nFor CORS middleware, the parameters are: `CORSMiddleware(allow_origins, allow_methods, allow_headers, max_age, allow_credentials)`.\n\nYou can create your own custom middleware by inherting from `IMiddleware` interface and implementing the `handle` method.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotz1480%2Fteapot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgotz1480%2Fteapot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotz1480%2Fteapot/lists"}