{"id":24312851,"url":"https://github.com/nicolaspearson/csharp.heroes.api","last_synced_at":"2025-06-25T00:07:46.952Z","repository":{"id":96017530,"uuid":"177194590","full_name":"nicolaspearson/csharp.heroes.api","owner":"nicolaspearson","description":"A simple REST API that provides CRUD operations on a hero object, it was built using C# and PostgreSQL.","archived":false,"fork":false,"pushed_at":"2019-03-24T16:53:21.000Z","size":156,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T11:52:28.605Z","etag":null,"topics":["csharp","entity-framework"],"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/nicolaspearson.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":"2019-03-22T18:57:47.000Z","updated_at":"2019-03-24T16:53:23.000Z","dependencies_parsed_at":"2023-07-09T20:32:24.759Z","dependency_job_id":null,"html_url":"https://github.com/nicolaspearson/csharp.heroes.api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nicolaspearson/csharp.heroes.api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolaspearson%2Fcsharp.heroes.api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolaspearson%2Fcsharp.heroes.api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolaspearson%2Fcsharp.heroes.api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolaspearson%2Fcsharp.heroes.api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicolaspearson","download_url":"https://codeload.github.com/nicolaspearson/csharp.heroes.api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolaspearson%2Fcsharp.heroes.api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261777695,"owners_count":23208126,"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":["csharp","entity-framework"],"created_at":"2025-01-17T08:30:36.364Z","updated_at":"2025-06-25T00:07:46.928Z","avatar_url":"https://github.com/nicolaspearson.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C# Heroes API\n\nA simple REST API that provides CRUD operations on a `hero` object, it was built using C# and PostgreSQL.\n\n## Getting Started\n\n**1. Clone the application**\n\n```bash\ngit clone https://github.com/nicolaspearson/csharp.heroes.api.git\n```\n\n**2. Start the database**\n\n```bash\ndocker-compose up\n```\n\n**3. Migrations**\n\nCreate the initial migrations, if they do not exist:\n\n```bash\ndotnet ef migrations add initial\n```\n\nRun the migrations:\n\n```bash\ndotnet ef database update\n```\n\n**4. Build and run the app**\n\n#### Run the app in development mode:\n\n```bash\ndotnet run -c Debug --project ./src/HeroApi/HeroApi.csproj\n```\n\nThe app will start running at \u003chttp://localhost:8000\u003e\n\n#### Run the app in release mode:\n\n```bash\ndotnet run -c Release --project ./src/HeroApi/HeroApi.csproj\n```\n\nThe app will start running at \u003chttp://localhost:8000\u003e\n\n## How I Created The Project\n\nBelow are details of how I created the `Web Api` and `Test` projects.\n\n### Web Api\n\nCreate the `src` directory:\n\n```bash\nmkdir src\n```\n\nInitialize the Web Api Project:\n\n```bash\ncd src\ndotnet new webapi -o HeroApi\n```\n\nAdd PostgreSQL packages:\n\n```bash\ncd ./src/HeroApi\ndotnet add package Npgsql.EntityFrameworkCore.PostgreSQL\ndotnet add package NpgSql.EntityFrameworkCore.PostgreSQL.Design\n```\n\nAdded connection string to `appsettings.json`:\n\n```csharp\n{\n  ...\n  \"ConnectionStrings\": {\n    \"DefaultConnection\": \"Host=localhost;Port=5432;Username=master;Password=masterkey;Database=hero;\"\n  }\n}\n```\n\nConnect to the database in the `Startup` class:\n\n```csharp\n  ...\n  public void ConfigureServices(IServiceCollection services)\n  {\n      services.AddDbContext\u003cHeroContext\u003e(options =\u003e options.UseNpgsql(Configuration.GetConnectionString(\"DefaultConnection\")));\n      ...\n  }\n  ...\n```\n\nFinally create your models, and controllers.\n\n### Testing\n\nCreate the `test` directory:\n\n```bash\nmkdir test\n```\n\nInitialize the Test Project:\n\n```bash\ncd test\ndotnet new xunit -o HeroApi.IntegrationTests\n```\n\nAdd Testing packages:\n\n```bash\ncd ./test/HeroApi.IntegrationTests\ndotnet add package Microsoft.AspNetCore.Mvc.Testing\ndotnet add package Microsoft.AspNetCore.App\n```\n\nAdd a Reference to the Web Api project:\n\n```bash\ncd ./test/HeroApi.IntegrationTests\ndotnet add reference ../../src/HeroApi/HeroApi.csproj\n```\n\nRun the tests:\n\n```bash\ncd ./test/HeroApi.IntegrationTests\ndotnet test\n```\n\n### Further Reading\n\nCheck [this](https://fullstackmark.com/post/20/painless-integration-testing-with-aspnet-core-web-api) article for a more detailed explanation.\n\n## Endpoints\n\nThe following endpoints are available:\n\n```\nGET /hero/{heroId}\n```\n\n```\nGET /hero\n```\n\n```\nPOST /hero\n```\n\n```\nPUT /hero/{heroId}\n```\n\n```\nDELETE /hero/{heroId}\n```\n\n## Benchmarking\n\nRun this command to benchmark request performance:\n\n```\nwrk -d1m http://localhost:8000/hero\n```\n\n![benchmark](/img/benchmark.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolaspearson%2Fcsharp.heroes.api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicolaspearson%2Fcsharp.heroes.api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolaspearson%2Fcsharp.heroes.api/lists"}