Asd.HttpLib 0.1.12

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Asd.HttpLib --version 0.1.12
                    
NuGet\Install-Package Asd.HttpLib -Version 0.1.12
                    
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="Asd.HttpLib" Version="0.1.12" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Asd.HttpLib" Version="0.1.12" />
                    
Directory.Packages.props
<PackageReference Include="Asd.HttpLib" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Asd.HttpLib --version 0.1.12
                    
#r "nuget: Asd.HttpLib, 0.1.12"
                    
#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.
#:package Asd.HttpLib@0.1.12
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Asd.HttpLib&version=0.1.12
                    
Install as a Cake Addin
#tool nuget:?package=Asd.HttpLib&version=0.1.12
                    
Install as a Cake Tool

Asd.HttpLib.

Сервер.

Для работы с ASP.NET.

Program.cs

using Asd.HttpLib.AspNet;

В WebApplicationBuilder вызвать метод расширения "AddAsdHttpServer".

builder.Services.AddAsdHttpServer();

Далее для WebApplication добавить указать типы классов, которые будут содержать методы для ответов на запросы.

app.UseAsdHttpService<ClassName>();

При необходимость можно указать заголовки для ответа на запросы для данного типа.

app.UseAsdHttpService<ClassName>( x => x.AddHeader("Access-Control-Allow-Origin", "*") );

Структура класса.

Можно использовать в конструкторе другие сервисы ASP.NET.

public ClassName( Singleton singleton ) {
  _singleton = singleton;
}

Для обработки запросов используются методы с аннотацией [HttpMethod]

[HttpMethod]
public string SayHello( string name ) {
  return $"Hello, {name}!!!"
}

В таком случае по адресу ${ASP_URL}/SayHello/ можно отправить post запрос. У аннотации HttpMethod есть конструктор, принимающий строку. Эта строка перезаписывает имя метода.

[HttpMethod("say_hello")]
public string SayHello( string name )
...

В данной ситуации адрес будет не "${ASP_URL}/SayHello/", а "${ASP_URL}/say_hello/". Типы входных и выходных данный сериализуются автоматически. Примитивы отправляются в виде обычной строки.

...
return 12;
...

Такой вариант придет клиенту как "12". Непримитивные объекты передаются в виде JSON.

class Student {
  string Name;
}

Если класс Student будет возвращаемым типом метода, то клиент получит ответ в виде.

"{ "Name": "andrewmat2000" }"

Можно использовать несколько входных параметров. Например:

[HttpMethod("login")]
public bool Login( string username, string password ) {
  return username == UserName && password == Password;
}

Для этого агрументы со стороны клиента необходимо разделить ';'.

`${username};${password}`

Клиент.

using HttpClient = Asd.HttpLib.HttpClient;

HttpClient client = new("http://localhost/");  // Uri.

var value = client.Get<T>("method_name");  // T - Expected type.

// Request uri will be http://localhost/method_name/

if (!value) {
  // If response cannot be deserialized.
  throw new("No answer");
}
// Else you can use object with property Value.
T ob = value.Value;
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 was computed.  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 was computed.  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 was computed.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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

Notes