Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
viceroypenguin committed Mar 20, 2024
1 parent 765fecf commit 9701187
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,50 @@
[![GitHub issues-closed](https://img.shields.io/github/issues-closed/viceroypenguin/Immediate.Apis.svg)](https://GitHub.com/viceroypenguin/Immediate.Apis/issues?q=is%3Aissue+is%3Aclosed)
[![GitHub Actions](https://github.com/viceroypenguin/Immediate.Apis/actions/workflows/build.yml/badge.svg)](https://github.com/viceroypenguin/Immediate.Apis/actions)
---

Immediate.Apis is a source generator for minimal APIs, for
[`Immediate.Handlers`](https://github.com/viceroypenguin/Immediate.Handlers) handlers. Simply add a `[MapGet]` to the
`[Handler]` class and an endpoint will automatically be added.

#### Examples
* [Immediate.Apis.FunctionalTests](./tests/Immediate.Apis.FunctionalTests)

## Installing Immediate.Apis

You can install [Immediate.Apis with NuGet](https://www.nuget.org/packages/Immediate.Apis):

Install-Package Immediate.Apis

Or via the .NET Core command line interface:

dotnet add package Immediate.Apis

Either commands, from Package Manager Console or .NET Core CLI, will download and install Immediate.Handlers.

## Using Immediate.Apis
### Creating an Endpoint

Create a Handler and an endpoint by adding the following code:

```cs
[Handler]
[MapGet("/users")]
public static partial class GetUsersQuery
{
public record Query;

private static ValueTask<IEnumerable<User>> HandleAsync(
Query _,
UsersService usersService,
CancellationToken token)
{
return usersService.GetUsers();
}
}
```

### Registering the endpoints

In your `Program.cs`, add a call to `app.MapXxxEndpoints()`, where `Xxx` is the shortened form of the project name.
* For a project named `Web`, it will be `app.MapWebEndpoints()`
* For a project named `Application.Web`, it will be `app.MapApplicationWebEndpoints()`

0 comments on commit 9701187

Please sign in to comment.