Skip to content

About

Sample project for using TypedRest for .NET

Resources

Stars

4 stars

Watchers

1 watching

Forks

Repository files navigation

TypedRest Address Book Sample

This is a sample project for using TypedRest for .NET. It provides a simple REST API for storing contacts in an address book and uses SQLite for persistance.

The code is split into:

OpenAPI

The Service describes itself with an OpenAPI document, served at /openapi/v1.json together with an interactive API reference at /scalar.

The same document is also written to Service/AddressBook.json on every build, so changes to the API show up in diffs.

Generated client

The GeneratedClient/ project uses the TypedRest source generator to build a client from Service/AddressBook.json during compilation:

<TypedRestOpenApi Include="..\Service\AddressBook.json" ServiceName="AddressBook" Serializer="system-text-json" />

The project depends on the Service only for build ordering, so the document is regenerated before the client is compiled. Endpoints, DTOs and a constructor taking the base URI (configured for System.Text.Json) are generated. AddressBookClient.cs adds one more constructor in a partial class, which takes a custom HttpClient for testing. The generated code is written to GeneratedClient/obj/ for inspection.

Compare it with the handwritten Client/, which produces the same endpoint structure but shares its DTOs with the Service.

About

Sample project for using TypedRest for .NET

Resources

Stars

4 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages