Poster.Core
0.0.2
dotnet add package Poster.Core --version 0.0.2
NuGet\Install-Package Poster.Core -Version 0.0.2
<PackageReference Include="Poster.Core" Version="0.0.2" />
paket add Poster.Core --version 0.0.2
#r "nuget: Poster.Core, 0.0.2"
// Install Poster.Core as a Cake Addin
#addin nuget:?package=Poster.Core&version=0.0.2
// Install Poster.Core as a Cake Tool
#tool nuget:?package=Poster.Core&version=0.0.2
Description
This library helps to build a HTTP service very quickly with embedded serialization and deserialization. You just need create interface, mark HTTP methods with attributes (GET, POST, DELETE etc.) and Poster will create your interface implementation for you.
HTTP service implementation example
public interface IOrderService
{
[Get("https://test.com/order/{id}")]
public Task<Order> GetOrderAsync(int id);
[Post("https://test.com/order")]
public Task CreateOrder([Body] Order order);
}
Instrance creation
var poster = new PosterBuilder()
// Here you can add build configuration
.Build();
var orderService = poster.BuildService<IOrderService>();
var order = await orderService.GetOrderAsync(10);
Supported HTTP requests
Poster support all main request types: GET, POST, PUT, PATCH, DELETE. You need to mark your method in service interface via GetAttribute
, PostAttribute
, PutAttribute
, PatchAttribute
or DeleteAttribute
accordingly.
Each http attribute has constructor with url parameter. Service will do request to this url addres.
Url supports inline parameters. Parameter should be covered in bracket {}
and method should contains this parameter as argument with the same name.
Method with parameters example
[Get("https://test.com/order/{id}")]
Task<Order> GetOrderAsync(int id);
[Post("https://test.com/message/{testParam}?param={param}")]
Task<Message> CreateMessageAsync(string testParam, double param);
Method return requirements
Each method in your service should returns Task
or Task<TResponseModel>
.
Http request body
If you want to send request body, you can add it to your method as argument and mark it via BodyAttribute
Request body example
[Post("https://test.com/order")]
Task CreateOrderAsync([Body] Order order);
Warning: only POST, PUT, PATCH methods support request body.
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows |
.NET Core | netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.1 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.NETStandard 2.1
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Poster.Core:
Package | Downloads |
---|---|
Poster
Package Description |
|
Poster.Http
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.0.2 | 576 | 1/13/2021 |