OutWit.Communication.Server.Rest 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package OutWit.Communication.Server.Rest --version 1.0.0                
NuGet\Install-Package OutWit.Communication.Server.Rest -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OutWit.Communication.Server.Rest" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OutWit.Communication.Server.Rest --version 1.0.0                
#r "nuget: OutWit.Communication.Server.Rest, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install OutWit.Communication.Server.Rest as a Cake Addin
#addin nuget:?package=OutWit.Communication.Server.Rest&version=1.0.0

// Install OutWit.Communication.Server.Rest as a Cake Tool
#tool nuget:?package=OutWit.Communication.Server.Rest&version=1.0.0                

OutWit.Communication.Server.Rest

Overview

The OutWit.Communication.Server.Rest library extends WitCom to support RESTful communication. It provides tools to expose services via REST APIs with advanced features like authentication, request processing, and logging. This package is ideal for scenarios requiring lightweight, scalable HTTP-based communication.

Features

1. REST API Server

  • Seamlessly expose services over HTTP.
  • Automatically maps HTTP requests to service methods.

2. Authentication and Authorization

  • Token-based authentication.
  • Customizable access control mechanisms.

3. Customizable Request Processing

  • Supports both GET and POST requests.
  • Allows custom logic for processing incoming requests and parameters.

4. Logging and Debugging

  • Integrated support for logging errors and request/response cycles.

Installation

Install the package via NuGet:

Install-Package OutWit.Communication.Server.Rest

Getting Started

Basic Setup

using OutWit.Communication.Server.Rest;

var server = WitComServerRestBuilder.Build(options =>
{
    options.WithUrl("http://localhost:5000/");
    options.WithService(new MyService());
    options.WithAccessToken("my-secret-token");
    options.WithLogger(new ConsoleLogger());
    options.WithTimeout(TimeSpan.FromMinutes(5));
});

server.StartWaitingForConnection();

Exposing a Service

Define your service with public methods to be exposed via REST API.

public class MyService
{
    public string Greet(string name)
    {
        return $"Hello, {name}!";
    }
}

Access this service with:

GET http://localhost:5000/Greet?name=John

Response:

"Hello, John!"

Advanced Configuration

Custom Request Processor

You can define custom logic for processing incoming requests:

using OutWit.Communication.Server.Rest;

var server = WitComServerRestBuilder.Build(options =>
{
    options.WithUrl("http://localhost:5000/");
    options.WithRequestProcessor(new CustomRequestProcessor());
});
Disable Authorization

Disable authorization entirely for public APIs:

var server = WitComServerRestBuilder.Build(options =>
{
    options.WithUrl("http://localhost:5000/");
    options.WithoutAuthorization();
});
Logging Support

Integrate logging for debugging and monitoring:

var server = WitComServerRestBuilder.Build(options =>
{
    options.WithUrl("http://localhost:5000/");
    options.WithLogger(new MyCustomLogger());
});

API Reference

WitComServerRest

The core server class that handles HTTP requests and responses.

Methods
  • StartWaitingForConnection(): Starts listening for incoming connections.
  • StopWaitingForConnection(): Stops the server and releases resources.

WitComServerRestBuilder

Provides a fluent interface for configuring and creating a WitComServerRest instance.

Configuration Options
  • .WithUrl(string url): Sets the server's base URL.
  • .WithService<TService>(TService service): Binds a service instance to the server.
  • .WithAccessToken(string token): Enables token-based authentication.
  • .WithoutAuthorization(): Disables authentication.
  • .WithLogger(ILogger logger): Configures logging.
  • .WithTimeout(TimeSpan timeout): Sets request timeout.

Error Handling

Errors encountered during request processing are logged and returned as HTTP responses with appropriate status codes.

Example error response:

{
  "status": 400,
  "message": "Failed to process request"
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 77 2/1/2025
1.1.0 62 1/25/2025
1.0.2 42 1/11/2025
1.0.0 89 1/2/2025