{"id":17349007,"url":"https://github.com/gwali-1/swytch","last_synced_at":"2025-04-14T21:12:24.989Z","repository":{"id":223008711,"uuid":"758738364","full_name":"Gwali-1/Swytch","owner":"Gwali-1","description":"Lightweight web framework in C#","archived":false,"fork":false,"pushed_at":"2025-04-07T08:39:48.000Z","size":616,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T21:12:15.249Z","etag":null,"topics":["api","class-library","csharp","framework","library","web-development","webframework"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Gwali-1.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":"2024-02-17T00:35:32.000Z","updated_at":"2025-04-07T08:39:51.000Z","dependencies_parsed_at":"2024-02-21T01:00:51.020Z","dependency_job_id":"e0b6b6c8-a042-4b4d-816e-2b16cdbaab07","html_url":"https://github.com/Gwali-1/Swytch","commit_stats":null,"previous_names":["gwali-1/swytch"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gwali-1%2FSwytch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gwali-1%2FSwytch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gwali-1%2FSwytch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gwali-1%2FSwytch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gwali-1","download_url":"https://codeload.github.com/Gwali-1/Swytch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248961236,"owners_count":21189993,"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":["api","class-library","csharp","framework","library","web-development","webframework"],"created_at":"2024-10-15T16:54:20.827Z","updated_at":"2025-04-14T21:12:24.978Z","avatar_url":"https://github.com/Gwali-1.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- LOGO --\u003e\n\n\u003cp align=\"center\"\u003e\n \u003cimg src=\"https://github.com/Gwali-1/Swytch/blob/main/Swytch/Logos/logo-1.png?raw=true\" width=300 height=150\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n   Lightweight, Fast and Alternative.\n    \u003cbr /\u003e\n    \u003ca href=\"#about\"\u003eAbout\u003c/a\u003e\n    ·\n    \u003ca href=\"#\"\u003eDocumentation\u003c/a\u003e\n    ·\n    \u003ca href=\"#\"\u003eNuget\u003c/a\u003e\n\u003c/p\u003e\n\n[![.NET](https://github.com/Gwali-1/Swytch/actions/workflows/dotnet_build.yml/badge.svg)](https://github.com/Gwali-1/Swytch/actions/workflows/dotnet_build.yml)\n[![Release](https://github.com/Gwali-1/Swytch/actions/workflows/release.yml/badge.svg)](https://github.com/Gwali-1/Swytch/actions/workflows/release.yml)\n\n---\n\n\n\n\n# About\n\nSwytch is a web framework written in C#. It is lightweight, fast and offers an alternative and refreshing\nway to author web services like REST APIs, web applications and static sites.It provides an expressive routing API, built-in\ntemplating with RazorLight, support for asynchronous job\nprocessing using Actors, and seamless database integration with Dapper.\n\n\n\u003e I started Swytch as an educational project to explore C# as a language and to experiment with a lightweight\n\u003e alternative\n\u003e for building simple web services or hacking on personal projects without the overhead of ASP.NET/ASP.NET CORE. It has\n\u003e been a\n\u003e rewarding experience, and I learned a lot along the way.\n\u003e I work on Swytch in my spare time, balancing it with my professional life and the other million things I have on my\n\u003e desk. It took almost a year to get Swytch to a point where\n\u003e I felt it was stable enough to share. Since I only work on this when I can afford to, I kindly ask for patience when\n\u003e raising issues or reporting bugs. I'll address them as soon as I can.\n\n#### Check out the [documentation](#) for more information\n\n#### Check out the [devlogs and architectural notes ](https://github.com/Gwali-1/Swytch/blob/main/Notes/notes_26_06_24.md)\n\n## Features\n\n- **Minimal and Expressive Routing** – Define routes and handler methods easily with a clean API.\n- **Path Parameters** – Extract parameters directly from the URL for dynamic routing.\n- **Templating with RazorLight** – Supports Razor-based templating for rendering dynamic content.\n- **Precompiled Templates** – Improves performance by precompiling Razor templates before execution.\n- **Built-in Lightweight ORM** – Includes **Dapper** for efficient database interaction.\n- **Asynchronous Job Processing** – Allows users to execute background and non-blocking tasks using **Actors**.\n- **Resilient Request Handling** – Exceptions occurring during a request are **isolated to that request**, preventing\n  failures from affecting the entire application.\n- **Middleware Support** – Extend functionality by adding middleware for request/response processing.\n- **Fast and Lightweight** – Designed for high performance with minimal overhead.\n\n## 📦 Installation\n\n---\n\nInstall **Swytch** via [NuGet](#):\n\n```sh\n dotnet add package Swytch\n```\n\nSwytch supports **.NET 6+**.\n\n## Basic Swytch Api\n\nCreate a basic **Swytch** application:\n\n```csharp\n//create a swytchapp\nvar app = new SwytchApp();\n\n//set up route \napp.AddAction(\"GET\", \"/\", async (context) =\u003e {\n    context.ToOk(\"Welcome to Swytch!\");\n});\n\n//start app\nawait swytchApp.Listen(); \n```\n\nRun the application and navigate to `http://localhost:8080/`.\n\n## Routing \u0026 Handlers\n\n\nDefine dynamic routes with path parameters:\n\n```csharp\napp.AddAction(\"GET\",\"/users/{id}\", async (context) =\u003e { \n    //get the id value\n    var id = context.PathParams[\"id\"];\n});\n\n\n\napp.AddAction(\"POST\",\"/users/{id}\", async (context) =\u003e { \n  //get the id value\n   string userId;\n   if(context.PathParams.TryGetValue(\"id\", out userId)){\n        //use here \n   }\n});\n\n\n//Register multiple HTTP methods to one handler\napp.AddAction(\"GET,POST\",\"/users/{id}\", async (context) =\u003e { \n    //get the id value\n    var id = context.PathParams[\"id\"];\n)};\n\n```\n\n## Middleware\n\nRegister **middleware**\n\n```csharp\napp.AddMiddleware(async (context) =\u003e\n{\n    Console.WriteLine(\"Incoming request...\");\n});\n```\n\n## Templating with RazorLight\n\n\nUse **RazorLight** to render dynamic template file:\n\n```csharp\nawait app.RenderTemplate(context, \"templateKey\", Books);\n```\n\n## Background  Jobs (Actors)\n\n\nExecute **background tasks** using **Actors**:\n\n```csharp\n//Initialize actor pool and register an actor\nActorPool.InitializeActorPool(serviceProvider);\nActorPool.Register\u003cTalkingActor\u003e();\n\n\n//Execute task using actor\n ActorPool.Tell\u003cTalkingActor,string\u003e(\"Home\");\n```\n\n## Database Integration (Dapper)\n\nQuery databases easily using **Dapper**:\n\n```csharp\n//Add data store \nswytchApp.AddDatastore(\"your_connection_string\", DatabaseProviders.SQLite);\n\n//execute query\n using IDbConnection dbConnection = app.GetConnection(DatabaseProviders.SQLite);\n var users = await dbConnection.QueryAsync\u003cUser\u003e(\"SELECT * FROM Users\");\n```\n\n## Contributing\n\n\nContributions are highly valued(seriously), whether it's proposing new features, suggesting improvements, or reporting bugs. Your\ninput helps make Swytch even better — feel free to submit a PR! \n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgwali-1%2Fswytch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgwali-1%2Fswytch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgwali-1%2Fswytch/lists"}