{"id":17255594,"url":"https://github.com/ffmathy/fluffyspoon.aspnet.templates","last_synced_at":"2026-06-30T23:32:25.391Z","repository":{"id":52451496,"uuid":"101639660","full_name":"ffMathy/FluffySpoon.AspNet.Templates","owner":"ffMathy","description":"A library allowing users to use Razor as markup in a template, with API operations from ASP .NET Controllers.","archived":false,"fork":false,"pushed_at":"2025-01-15T09:18:17.000Z","size":29,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-22T19:43:57.670Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ffMathy.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,"zenodo":null}},"created_at":"2017-08-28T12:12:44.000Z","updated_at":"2019-03-18T20:51:27.000Z","dependencies_parsed_at":"2025-04-21T23:39:27.969Z","dependency_job_id":null,"html_url":"https://github.com/ffMathy/FluffySpoon.AspNet.Templates","commit_stats":null,"previous_names":["ffmathy/fluffyspoon.templates"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ffMathy/FluffySpoon.AspNet.Templates","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ffMathy%2FFluffySpoon.AspNet.Templates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ffMathy%2FFluffySpoon.AspNet.Templates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ffMathy%2FFluffySpoon.AspNet.Templates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ffMathy%2FFluffySpoon.AspNet.Templates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ffMathy","download_url":"https://codeload.github.com/ffMathy/FluffySpoon.AspNet.Templates/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ffMathy%2FFluffySpoon.AspNet.Templates/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281544212,"owners_count":26519552,"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","status":"online","status_checked_at":"2025-10-28T02:00:06.022Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-15T07:12:07.914Z","updated_at":"2025-10-29T01:36:25.469Z","avatar_url":"https://github.com/ffMathy.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FluffySpoon.AspNet.Templates\nA library allowing users to use Razor as markup in a template, with API operations from ASP .NET Controllers without making HTTP requests.\n\nUseful if you are hosting a system (for instance a webshop system) where the user can modify his templates (cshtml files). By using this approach, the user gets all the flexibility of the shop system's API, but it is rendered server-side (so safe and hidden from the webbrowser).\n\nThis also has the benefit of you only having to worry about your own API and its scalability and stability. In other words, dogfeeding your own stuff.\n\n## Usage\nTo use the templating system, 3 steps are required.\n\n### Wiring up\nAdd the following to the `Startup.cs` file's `ConfigureServices` method right after the `services.AddMvc` invocation.\n\n`services.AddFluffySpoonTemplating();`\n\n### Writing some API controllers\nLet's say we have the following two controllers.\n\n```csharp\npublic class GroupController : Controller\n{\n\t[HttpGet(\"api/groups\")]\n\tpublic string[] GetAllGroups()\n\t{\n\t\treturn new[]\n\t\t{\n\t\t\t\"foo\", \"bar\"\n\t\t};\n\t}\n}\n\npublic class UserController : Controller\n{\n    [HttpGet(\"api/users/{userId}\")]\n    public string GetUsername(int userId)\n    {\n        return \"username\" + userId;\n    }\n}\n```\n\n### Writing a view\nThe above controllers can of course be invoked via HTTP(S) calls, but `FluffySpoon.Templates` allow using the API in Razor directly, without making HTTP(S) calls at all.\n\n**Views/MyView.cshtml**\n```razor\n@model ApiModel\n\n\u003ch1\u003eWelcome @Model.Get(\"/api/users/1337\")\u003c/h1\u003e\n\n@foreach(var groupName in Model.GetCollection\u003cstring\u003e(\"/api/groups\"))\n{\n    \u003ch2\u003e@groupName\u003c/h2\u003e\n}\n```\n\n### Rendering the view\nIf we want to render the view, we can then write a controller that does it for us.\n\n```csharp\npublic class HomeController : Controller\n{\n    private readonly IFluffySpoonTemplateRenderer _templateRenderer;\n\n    public HomeController(\n        IFluffySpoonTemplateRenderer templateRenderer)\n    {\n        _templateRenderer = templateRenderer;\n    }\n\n    public async Task\u003cIActionResult\u003e Index()\n    {\n        //here we specify that only UserController and GroupController can be invoked via the view.\n        var html = await _templateRenderer.RenderAsync(\n            \"MyView\",\n            new UserController(),\n            new GroupController());\n        return Content(html, \"text/html\");\n    }\n}\n```\n\nThe result is seen below.\n\n```html\n\u003ch1\u003eWelcome username1337\u003c/h1\u003e\n\n\u003ch2\u003efoo\u003c/h2\u003e\n\u003ch2\u003ebar\u003c/h2\u003e\n```\n\n## Is this safe for production use?\nYes. With this library, it is impossible to use anything else than `Model` and its properties in a view file. If you (for instance) try to invoke unsafe code like in `System.Reflection`, the view will not run and throw a `ViewValidationException`.\n\nThere is no magic going on in this library. I use Microsoft's routing engine, their Razor engine and action selector engine straight out of ASP .NET Core. This means that there is no funky behavior involved.\n\nFor the validation part, I use Roslyn to very strictly only allow any form of statement from `Model` in the view.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fffmathy%2Ffluffyspoon.aspnet.templates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fffmathy%2Ffluffyspoon.aspnet.templates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fffmathy%2Ffluffyspoon.aspnet.templates/lists"}