Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anishkny/dotnet-minimal-api-example
ASP.NET Minimal API Tutorial with Postman tests and code coverage
https://github.com/anishkny/dotnet-minimal-api-example
coverage csharp dotnet postman
Last synced: about 1 month ago
JSON representation
ASP.NET Minimal API Tutorial with Postman tests and code coverage
- Host: GitHub
- URL: https://github.com/anishkny/dotnet-minimal-api-example
- Owner: anishkny
- License: mit
- Created: 2023-08-24T23:13:02.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-15T04:30:14.000Z (7 months ago)
- Last Synced: 2024-04-24T02:43:39.872Z (7 months ago)
- Topics: coverage, csharp, dotnet, postman
- Language: C#
- Homepage: https://learn.microsoft.com/en-us/aspnet/core/tutorials/min-web-api
- Size: 1.05 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# .NET Minimal API Example
[![CI](https://github.com/anishkny/dotnet-minimal-api-example/actions/workflows/ci.yml/badge.svg)](https://github.com/anishkny/dotnet-minimal-api-example/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/anishkny/dotnet-minimal-api-example/graph/badge.svg)](https://codecov.io/gh/anishkny/dotnet-minimal-api-example)This repository follows along and implements this tutorial: [Create a minimal API with ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/tutorials/min-web-api?view=aspnetcore-7.0&tabs=visual-studio-code).
> Minimal APIs are architected to create HTTP APIs with minimal dependencies. They are ideal for microservices and apps that want to include only the minimum files, features, and dependencies in ASP.NET Core.
## Getting Started
### Prerequisites
- [.NET SDK](https://dotnet.microsoft.com/download) (Version 7 or later)
- [Node.js](https://nodejs.org/en/) (Version 18 or later)
- [PostgreSQL](https://www.postgresql.org/) (Version 15 or later)### Installation
1. Clone this repository
```bash
git clone https://github.com/anishkny/dotnet-minimal-api-example.git
```2. Install dependencies
```bash
cd dotnet-minimal-api-example
npm install
```### Usage
1. Start a PostgreSQL server
```bash
docker run -p 5432:5432 -e 'POSTGRES_PASSWORD=password' postgres:15-alpine
```Alternately, you can specify a custom environment variable `POSTGRES_CONNECTION_STRING` to connect to a PostgreSQL server running elsewhere.
2. Run the application
```bash
npm run build
npm run start
```3. Open a browser and navigate to [http://localhost:5000/todoitems](http://localhost:5000/todoitems)
### Migrations
If you make changes to the database models, you will need to generate a new migration and apply it to the database.
```bash
dotnet ef migrations add -o migrations
```All migrations are stored in the [`src/migrations`](./src/migrations) directory.
### Running Tests
```bash
npm run start-and-test
```### Postman Collection
Included is a Postman collection that can be used to test the API. You can import the collection by opening Postman and clicking on `File > Import...` and selecting the [`api-tests.postman_collection.json`](./api-tests.postman_collection.json) file.
![Postman Collection](./postman.png)
It is also used for automated testing via the `newman` tool.
### Coverage
After running the test suite, you can view the code coverage report by opening the `coveragereport/index.htm` file in a web browser.
## License
This project is licensed under the [MIT License](https://opensource.org/license/mit/) - see the [LICENSE](LICENSE) file for details.