SourceCrafter.HttpServiceClientGenerator
1.23.122.8
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
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 SourceCrafter.HttpServiceClientGenerator --version 1.23.122.8
NuGet\Install-Package SourceCrafter.HttpServiceClientGenerator -Version 1.23.122.8
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="SourceCrafter.HttpServiceClientGenerator" Version="1.23.122.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SourceCrafter.HttpServiceClientGenerator" Version="1.23.122.8" />
<PackageReference Include="SourceCrafter.HttpServiceClientGenerator" />
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 SourceCrafter.HttpServiceClientGenerator --version 1.23.122.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SourceCrafter.HttpServiceClientGenerator, 1.23.122.8"
#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 SourceCrafter.HttpServiceClientGenerator@1.23.122.8
#: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=SourceCrafter.HttpServiceClientGenerator&version=1.23.122.8
#tool nuget:?package=SourceCrafter.HttpServiceClientGenerator&version=1.23.122.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
🍰 HttPie: Next generation for Rest API Generation.
Sucessor for SourceCrafter.HttpServiceClient
You just can build/update/generate* your API calls
Under these premises
- Properties and indexers will generate path segments, encoded to url components
- Methods are HTTP verbs invokers for GET, DELETE, POST, PUT and PATCH requests (e.g.:
GetAsync(...)), with the following parameters (all of them are optional):TResponse?: Return type for the async methodTContent? content: For POST, PUT and PATCH requests content.TQuery? query: Generic parameter to be serialized into URL query componentsAction<HttpClient, HttpRequestMessage>? requestHandler: A handler for requests before send it to the serverUsage: Set some information to headers
Action<HttpClient, HttpResponseMessage>? requestHandler: A handler for after get the response and before serialize the possible content coming from the serverUsage: Gather information from response headers
CancellationToken? cancelToken: A cancellation token for this task
Operation metadata
| Key | Description |
|---|---|
queryParamName |
Sets the query parameter name. Defaults to query. E.g.: ?status=pending whereas status is the queryParamName for a value type parameter |
contentParamName |
Sets the content parameter name. Defaults to content. For MultipartFormData or FormUrlEncoded content types creates a named item for value type parameters |
contentFormatType |
Determines the content format type. MultipartFormData and FormUrlEncoded. For Xml, a StreamContent is created to transport the serialized data. Json uses the same System.Net.Http.Json.JsonContent are available |
responseFormatType |
Determines the response format type. Just Xml and Json |
Rest of
{key}: {value}pairs parsed on comments will be trated as request headers
The client
// Generates a client class with the following name convention
// Takes Name from I{Name}Api and adds 'Client' to the end
var _cakeClient = new PetStoreClient();
The usage
//will produce a call to https://petstore.swagger.io/v2/store/inventory
var inventory = await _cakeClient.Store.Inventory.GetAsync();
The structure (*generated)
[HttpOptions("https://petstore.swagger.io/v2/",
// Url Encode properties are formatted specific casing (CamelCase, PascalCase, Upper and Lower snake casing)
QueryCasing = Casing.CamelCase,
// Path segments casing format
PathCasing = Casing.CamelCase,
// Enum values casing format on query and path. None for its underlying value
EnumQueryCasing = Casing.CamelCase,
// Enum values casing format on content serialization
EnumSerializationCasing = Casing.CamelCase,
// Properties casing format on content serialization
PropertyCasing = Casing.CamelCase)]
public interface IPetStoreApi
{
IStore Store { get; }
IPet Pet { get; }
IUser User { get; }
}
public interface IStore
{
IOrder Order { get; }
IStoreInventory Inventory { get; }
}
public interface IPet
{
IPetActionsByPetId this[long petId] { get; }
IPetActionsByStatus FindByStatus { get; }
IOrderActions Order { get; }
}
public interface IOrder:
IPost<User, User>
{
IOrderActionsByOrderId this[int orderId] { get; }
}
public interface IOrderActionsByOrderId :
IGet<Order>,
IDelete<ApiResponse>
{
}
public interface IPetActionsByStatus :
// queryParamName: status
IGet<PetStatus, List<Pet>>
{
}
public interface IOrderActions:
IPost<Order, Order>,
IPut<Order, Order>
{
}
public interface IPetActionsByPetId :
IGet<Pet>,
IDelete<ApiResponse>,
IPost<Pet, Pet>
{
IPetActionsByPetIdUploadImage UploadImage { get; }
}
public interface IPetActionsByPetIdUploadImage :
// contentParamName: file
IPost<FileInfo, ApiResponse>
{
}
public interface IStoreInventory: IGet<Dictionary<string, long>>
{
}
public interface IUser:IPost<User, ApiResponse>
{
IUserActionsByUserName this[string userName] { get; }
}
public interface IUserActionsByUserName :
IGet<User>,
IDelete<ApiResponse>,
IPut<User, User>
{
}
The models
public enum PetStatus
{
Available, Pending, Sold
}
public enum OrderStatus
{
Placed, Approved, Delivered
}
public class Order
{
public int Id { get; set; }
public int PetId { get; set; }
public int Quantity { get; set; }
public DateTime ShipDate { get; set; }
public OrderStatus Status { get; set; }
public bool Complete { get; set; }
}
public class ApiResponse
{
public int Code { get; set; }
public string Type { get; set; }
public string Message { get; set; }
}
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Pet
{
public long Id { get; set; }
public Category Category { get; set; }
public string Name { get; set; }
public string[] PhotoUrls { get; set; }
public Tag[] Tags { get; set; }
public PetStatus Status { get; set; }
}
public class Tag
{
public int Id { get; set; }
public string Name { get; set; }
}
public class User
{
public long Id { get; set; }
public string Username { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public string Phone { get; set; }
public int UserStatus { get; set; }
public OrderStatus Status { get; set; }
}
Generated content
The following interface
public interface IPetActionsByPetIdUploadImage :
// contentParamName: file
IPost<FileInfo, ApiResponse>
{
}
would generate the following service class (based on the previous definition example):
//<auto generated>
using static SourceCrafter.HttpServiceClient.HttPieHelpers;
using System.Net.Http.Json;
using System.IO;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Threading;
using Domain.Service.Models;
using SourceCrafter.HttpServiceClient;
namespace Domain.Service
{
public class PetActionsByPetIdUploadImageService : IPetActionsByPetIdUploadImage
{
private readonly PetStoreAgent _agent;
private readonly string _path;
internal PetActionsByPetIdUploadImageService(PetStoreAgent agent, string path)
{
_agent = agent;
_path = path;
}
public async Task<ApiResponse> PostAsync(FileInfo file, Func<HttpRequestMessage, Task> beforeSend = default, Func<HttpResponseMessage, Task> afterSend = default, CancellationToken cancellationToken = default)
{
var request = new HttpRequestMessage(HttpMethod.Post, new Uri(_path, UriKind.Relative)) {
Content = HttPieHelpers.CreateMultipartFormData(ArrayFrom((file.ToByteArrayContent(), "file", file.Name)))
};
var response = await _agent._httpClient.SendAsync(request, cancellationToken);
return response switch
{
{ IsSuccessStatusCode: true, Content: {} responseContent } =>
await responseContent.ReadFromJsonAsync<ApiResponse>(_agent._jsonOptions, cancellationToken),
{ IsSuccessStatusCode: false } =>
throw new HttpRequestException(response.ReasonPhrase),
_ => default(ApiResponse)
};
}
}
}
TODO:
- Manage body and response content headers properly
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
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.24.71.5 | 320 | 3/11/2024 |
| 0.23.155.7 | 325 | 6/4/2023 |
| 0.23.149.66 | 292 | 5/29/2023 |
| 0.23.149.53 | 315 | 5/29/2023 |
| 0.23.148.16 | 309 | 5/28/2023 |
| 0.23.147.89 | 311 | 5/27/2023 |
| 0.23.144.75 | 327 | 5/24/2023 |
| 0.23.144.56 | 302 | 5/24/2023 |
| 0.23.144.52 | 319 | 5/24/2023 |
| 0.23.144.25 | 326 | 5/24/2023 |
| 0.23.122.13 | 300 | 5/2/2023 |
Package renaming