Skip to content

TypedRest/TypedRest-DotNet

Repository files navigation

TypedRest for .NET

Build API documentation
TypedRest helps you build type-safe, fluent-style REST API clients. Common REST patterns such as collections are represented as classes, allowing you to write more idiomatic code.

var client = new MyClient(new Uri("http://example.com/"));

// GET /contacts
List<Contact> contactList = await client.Contacts.ReadAllAsync();

// POST /contacts -> Location: /contacts/1337
ContactEndpoint smith = await client.Contacts.CreateAsync(new Contact {Name = "Smith"});
//ContactEndpoint smith = client.Contacts["1337"];

// GET /contacts/1337
Contact contact = await smith.ReadAsync();

// PUT /contacts/1337/note
await smith.Note.SetAsync(new Note {Content = "some note"});

// GET /contacts/1337/note
Note note = await smith.Note.ReadAsync();

// DELETE /contacts/1337
await smith.DeleteAsync();

Read a more detailed Introduction to TypedRest or jump right in with the Getting started guide.

You can also take a look at our Sample project.

NuGet packages

TypedRest
The main TypedRest library.

TypedRest.Reactive
Adds support for streaming with ReactiveX (Rx).
Create endpoints using the types in the TypedRest.Endpoints.Reactive namespace.

TypedRest.SystemTextJson
Adds support for serializing using System.Text.Json instead of Newtonsoft.Json.
Pass new SystemTextJsonSerializer() to the EntryEndpoint constructor.

TypedRest.OAuth
Adds support for OAuth 2.0 / OpenID Connect authentication to HttpClient.
Call .AddOAuthHandler() after .AddTypedRest() (or .AddHttpClient() when not using main TypedRest package).

TypedRest.CommandLine
Build command-line interfaces for TypedRest clients.
Create commands mirroring the endpoints using the types in the TypedRest.CommandLine.Commands namespace.

Building

The source code is in src/, config for building the API documentation is in doc/ and generated build artifacts are placed in artifacts/. The source code does not contain version numbers. Instead the version is determined during CI using GitVersion.

To build run .\build.ps1 or ./build.sh (.NET SDK is automatically downloaded if missing using 0install).

Contributing

We welcome contributions to this project such as bug reports, recommendations and pull requests.

This repository contains an EditorConfig file. Please make sure to use an editor that supports it to ensure consistent code style, file encoding, etc.. For full tooling support for all style and naming conventions consider using JetBrains' ReSharper or Rider products.