{"id":23740223,"url":"https://github.com/mustaddon/singleapi","last_synced_at":"2025-09-04T15:32:10.135Z","repository":{"id":62216900,"uuid":"534666065","full_name":"mustaddon/SingleApi","owner":"mustaddon","description":".NET Single/generic webapi endpoint for mediators","archived":false,"fork":false,"pushed_at":"2024-02-26T14:38:38.000Z","size":167,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-27T02:03:03.053Z","etag":null,"topics":["aspnetcore","cqrs","cqrs-api","cqrs-endpoint","dotnet","endpoint","generic-apis","generic-endpoint","mediator","mediator-api","mediator-endpoint","mediatr","minimal-api","rest-api","single-api","single-endpoint","webapi","webapi-extensions"],"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/mustaddon.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-09-09T14:00:28.000Z","updated_at":"2024-03-05T07:44:14.000Z","dependencies_parsed_at":"2024-11-16T12:21:47.701Z","dependency_job_id":"e1d6016d-a650-4166-84ff-e6a7556320b6","html_url":"https://github.com/mustaddon/SingleApi","commit_stats":{"total_commits":41,"total_committers":1,"mean_commits":41.0,"dds":0.0,"last_synced_commit":"3b7cb6dd4655942f06114ece82a526298a1cdaf2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustaddon%2FSingleApi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustaddon%2FSingleApi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustaddon%2FSingleApi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustaddon%2FSingleApi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mustaddon","download_url":"https://codeload.github.com/mustaddon/SingleApi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231970943,"owners_count":18453930,"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":["aspnetcore","cqrs","cqrs-api","cqrs-endpoint","dotnet","endpoint","generic-apis","generic-endpoint","mediator","mediator-api","mediator-endpoint","mediatr","minimal-api","rest-api","single-api","single-endpoint","webapi","webapi-extensions"],"created_at":"2024-12-31T09:47:30.013Z","updated_at":"2024-12-31T09:47:30.767Z","avatar_url":"https://github.com/mustaddon.png","language":"C#","readme":"# SingleApi [![NuGet version](https://badge.fury.io/nu/SingleApi.svg)](http://badge.fury.io/nu/SingleApi)\nSingle/generic WebApi endpoint for mediators\n\n\n## Features\n* Ready for mediators\n* Generics support\n* In/out file streams\n\n\n## Example 1: SingleApi with MediatR\n*.NET CLI*\n```\ndotnet new web --name \"SingleApiExample\"\ncd SingleApiExample\ndotnet add package SingleApi\ndotnet add package MediatR\n```\n\n*Change Program.cs*\n```C#\nusing MediatR;\nusing System.Reflection;\n\nvar builder = WebApplication.CreateBuilder(args);\n\nbuilder.Services.AddMediatR(cfg =\u003e cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));\n\nvar app = builder.Build();\n\napp.MapSingleApi(\"sapi\", \n    // invoke the MediatR\n    x =\u003e x.ServiceProvider.GetRequiredService\u003cIMediator\u003e().Send(x.Data, x.CancellationToken),\n    // assemblies for type resolving\n    Assembly.GetExecutingAssembly()); \n\napp.Run();\n```\n\n[Example project...](https://github.com/mustaddon/SingleApi/tree/main/Examples/Example.MediatR)\n\n\n## Example 2: Request/Response\n\n*Request*\n```\nGET /sapi/Ping?data={\"Message\":\"TEST\"}\n\nor\n\nPOST /sapi/Ping\n{\"Message\":\"TEST\"}\n```\n\n*Response*\n```\n{\"Message\":\"TEST PONG\"}\n```\n\n\n## Example 3: Generics requests\n```C#\napp.MapSingleApi(\"sapi\", \n    // for simplicity, return the received data\n    x =\u003e Task.FromResult(x.Data), \n    // existing generic types will suffice for this example\n    typeof(List\u003c\u003e).Assembly, typeof(int).Assembly); \n```\n\n*Request #1: Equivalent of List\\\u003cString\u003e*\n```\nPOST /sapi/List(String)\n[\"text1\",\"text2\",\"text3\"]\n```\n\n*Request #2: Equivalent of Dictionary\u003cstring,int?[]\u003e*\n```\nPOST /sapi/Dictionary(String-Array(Nullable(Int32)))\n{\"key1\":[555,null,777]}\n```\n\n\n## Example 4: .NET client\n*.NET CLI*\n```\ndotnet new console --name \"SapiClientExample\"\ncd SapiClientExample\ndotnet add package SingleApi.Client\n```\n\n*Program.cs:*\n```C#\nusing SingleApi.Client;\n\n// create client\nusing var sapi = new SapiClient(\"https://localhost:7263/sapi\");\n\n// send request\nvar response = await sapi.Send(new Ping { Message = \"TEST\" });\n\nConsole.WriteLine(response?.Message);\n```\n\n*Console output:*\n```\nTEST PONG\n```\n\n[Example project...](https://github.com/mustaddon/SingleApi/tree/main/Examples/Example.Client)\n\n\n## Example 5: File upload\n*Create RequestHandler*\n```C#\nusing MediatR;\nusing MetaFile;\nnamespace Example;\n\npublic class FileUpload : StreamFile, IRequest\u003cstring\u003e\n{\n\n}\n\npublic class FileUploadHandler : IRequestHandler\u003cFileUpload, string\u003e\n{\n    public async Task\u003cstring\u003e Handle(FileUpload request, CancellationToken cancellationToken)\n    {\n        var filePath = Path.GetFullPath(request.Name);\n        using var fileStream = File.Create(filePath);\n        await request.Content.CopyToAsync(fileStream, cancellationToken);\n        return filePath;\n    }\n}\n```\n\n*Sending a file in JavaScript*\n```js\nlet file = document.getElementById('my-input').files[0];\n\nlet response = await fetch('/sapi/FileUpload', {\n    method: 'POST',\n    headers: {\n        'content-type': file.type || 'application/octet-stream',\n        'content-disposition': `attachment; filename*=utf-8''${encodeURIComponent(file.name)}`,\n    },\n    body: file,\n});\n\nconsole.log('result:', await response.json());\n```\n\n[Example project...](https://github.com/mustaddon/SingleApi/tree/main/Examples/Example.MediatR)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmustaddon%2Fsingleapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmustaddon%2Fsingleapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmustaddon%2Fsingleapi/lists"}