![]() |
VOOZH | about |
dotnet add package RESTFulSense --version 3.2.0
NuGet\Install-Package RESTFulSense -Version 3.2.0
<PackageReference Include="RESTFulSense" Version="3.2.0" />
<PackageVersion Include="RESTFulSense" Version="3.2.0" />Directory.Packages.props
<PackageReference Include="RESTFulSense" />Project file
paket add RESTFulSense --version 3.2.0
#r "nuget: RESTFulSense, 3.2.0"
#:package RESTFulSense@3.2.0
#addin nuget:?package=RESTFulSense&version=3.2.0Install as a Cake Addin
#tool nuget:?package=RESTFulSense&version=3.2.0Install as a Cake Tool
👁 .NET
👁 Nuget
👁 Nuget
👁 The Standard - COMPLIANT
👁 The Standard
👁 The Standard Community
I designed & developed this library as a wrapper around the existing .NET Core HttpClient implementation to provide the following values:
Meaningful Exceptions for APIs response status codes.
Simplified API communications.
Test-friendly implementation.
You can get RESTFulSense Nuget package by typing:
Install-Package RESTFulSense
This library was built according to The Standard. The library follows engineering principles, patterns and tooling as recommended by The Standard.
This library is also a community effort which involved many nights of pair-programming, test-driven development and in-depth exploration research and design discussions.
The most important fulfillment aspect in a Standard complaint system is aimed towards contributing to people, its evolution, and principles. An organization that systematically honors an environment of learning, training, and sharing knowledge is an organization that learns from the past, makes calculated risks for the future, and brings everyone within it up to speed on the current state of things as honestly, rapidly, and efficiently as possible.
We believe that everyone has the right to privacy, and will never do anything that could violate that right. We are committed to writing ethical and responsible software, and will always strive to use our skills, coding, and systems for the good. We believe that these beliefs will help to ensure that our software(s) are safe and secure and that it will never be used to harm or collect personal data for malicious purposes.
The Standard Community as a promise to you is in upholding these values.
| Status | Code | Exception |
|---|---|---|
| BadRequest | 400 | HttpResponseBadRequestException |
| Unauthorized | 401 | HttpResponseUnauthorizedException |
| PaymentRequired | 402 | HttpResponsePaymentRequiredException |
| Forbidden | 403 | HttpResponseForbiddenException |
| NotFound | 404 | HttpResponseNotFoundException |
| NotFound | 404 | HttpResponseUrlNotFoundException |
| MethodNotAllowed | 405 | HttpResponseMethodNotAllowedException |
| NotAcceptable | 406 | HttpResponseNotAcceptableException |
| ProxyAuthenticationRequired | 407 | HttpResponseProxyAuthenticationRequiredException |
| RequestTimeout | 408 | HttpResponseRequestTimeoutException |
| Conflict | 409 | HttpResponseConflictException |
| Gone | 410 | HttpResponseGoneException |
| LengthRequired | 411 | HttpResponseLengthRequiredException |
| PreconditionFailed | 412 | HttpResponsePreconditionFailedException |
| RequestEntityTooLarge | 413 | HttpResponseRequestEntityTooLargeException |
| RequestUriTooLong | 414 | HttpResponseRequestUriTooLongException |
| UnsupportedMediaType | 415 | HttpResponseUnsupportedMediaTypeException |
| RequestedRangeNotSatisfiable | 416 | HttpResponseRequestedRangeNotSatisfiableException |
| ExpectationFailed | 417 | HttpResponseExpectationFailedException |
| MisdirectedRequest | 421 | HttpResponseMisdirectedRequestException |
| UnprocessableEntity | 422 | HttpResponseUnprocessableEntityException |
| Locked | 423 | HttpResponseLockedException |
| FailedDependency | 424 | HttpResponseFailedDependencyException |
| UpgradeRequired | 426 | HttpResponseUpgradeRequiredException |
| PreconditionRequired | 428 | HttpResponsePreconditionRequiredException |
| TooManyRequests | 429 | HttpResponseTooManyRequestsException |
| RequestHeaderFieldsTooLarge | 431 | HttpResponseRequestHeaderFieldsTooLargeException |
| UnavailableForLegalReasons | 451 | HttpResponseUnavailableForLegalReasonsException |
| InternalServerError | 500 | HttpResponseInternalServerErrorException |
| NotImplemented | 501 | HttpResponseNotImplementedException |
| BadGateway | 502 | HttpResponseBadGatewayException |
| ServiceUnavailable | 503 | HttpResponseServiceUnavailableException |
| GatewayTimeout | 504 | HttpResponseGatewayTimeoutException |
| HttpVersionNotSupported | 505 | HttpResponseHttpVersionNotSupportedException |
| VariantAlsoNegotiates | 506 | HttpResponseVariantAlsoNegotiatesException |
| InsufficientStorage | 507 | HttpResponseInsufficientStorageException |
| LoopDetected | 508 | HttpResponseLoopDetectedException |
| NotExtended | 510 | HttpResponseNotExtendedException |
| NetworkAuthenticationRequired | 511 | HttpResponseNetworkAuthenticationRequiredException |
API controllers in ASP.NET Core today don't offer the full range of HTTP Codes that can be used to communicate certain events and errors to end users, in this library we managed to implement all the missing methods to communicate the full range of error codes as follows:
| Controller Method | Code |
|---|---|
| PaymentRequired(object value) | 402 |
| MethodNotAllowed(object value) | 405 |
| NotAcceptable(object value) | 406 |
| ProxyAuthenticationRequired(object value) | 407 |
| RequestTimeout(object value) | 408 |
| Gone(object value) | 410 |
| LengthRequired(object value) | 411 |
| PreconditionFailed(object value) | 412 |
| RequestEntityTooLarge(object value) | 413 |
| RequestUriTooLong(object value) | 414 |
| UnsupportedMediaType(object value) | 415 |
| RequestedRangeNotSatisfiable(object value) | 416 |
| ExpectationFailed(object value) | 417 |
| MisdirectedRequest(object value) | 421 |
| UnprocessableEntity(object value) | 422 |
| Locked(object value) | 423 |
| FailedDependency(object value) | 424 |
| UpgradeRequired(object value) | 426 |
| PreconditionRequired(object value) | 428 |
| TooManyRequests(object value) | 429 |
| RequestHeaderFieldsTooLarge(object value) | 431 |
| UnavailableForLegalReasons(object value) | 451 |
| InternalServerError(object value) | 500 |
| NotImplemented(object value) | 501 |
| BadGateway(object value) | 502 |
| ServiceUnavailable(object value) | 503 |
| GatewayTimeout(object value) | 504 |
| HttpVersionNotSupported(object value) | 505 |
| VariantAlsoNegotiates(object value) | 506 |
| InsufficientStorage(object value) | 507 |
| LoopDetected(object value) | 508 |
| NotExtended(object value) | 510 |
| NetworkAuthenticationRequired(object value) | 511 |
This can be achieved by simply replacing the inheritance ControllerBase in your ASP.NET Core Controller class with RESTFulController as follows:
[ApiController]
[Route("api/[controller]")]
public class ContactsController : RESTFulController
{
...
}
Once that's done, you will have full access to use any of the methods above to communicate more meaningful errors to your API consumers and clients.
Passing or retrieving objects from an API should be as simple as one method call, for RESTFulSense, you don't have to worry about how to serialize your input or deserialize the API output, here's how simple it works:
The initialization of the RESTFulSense Client can be done in two different ways:
In your ASP.NET Core application, you can initialize the IRESTFulApiFactoryClient in your startup.cs as follows:
services.AddHttpClient<IRESTFulApiFactoryClient, RESTFulApiFactoryClient>(client => client.BaseAddress = new Uri(YOUR_API_URL));
You can also use the RESTFulClient simple initialize in a console app for instance as follows:
var apiClient = new RESTFulApiClient();
List<Student> students =
await restfulApiClient.GetContentAsync<List<Student>>(relativeUrl: "api/students");
Student student =
await restfulApiClient.PostContentAsync<Student>(relativeUrl: "api/students", content: inputStudent);
In addition to the wrappers around API calls and serialization/deserialization, this library also provides a simplified way to execute communications without any workarounds.
For instance, to execute a PUT API call without a body, to update a status for instance, you don't have to fake a PUT body to execute a successful call, you can just do the follows:
Account activatedAccount =
await restfulApiClient.PutContentAsync(relativeUrl: $"api/accounts/{accountId}/activate");
RESTFulSense allows you to easily convert a C# class with attributes into a MultipartFormDataContent and send it as a POST request using the PostFormAsync method.
The library includes the following attributes:
| Attribute | Description |
|---|---|
RESTFulByteArrayContentAttribute |
Specifies a byte array content type |
RESTFulStreamContentAttribute |
Specifies a stream content type |
RESTFulStringContentAttribute |
Specifies a string content type |
RESTFulFileNameAttribute |
Adds a file name to the content |
These attributes allow you to specify the content types and names of the form data. The RESTFulFileNameAttribute also allows you to add a file name to the content. Simply apply the attributes to your class properties and the library will handle the rest.
Here's an example usage:
public class FormUpload
{
[RESTFulStreamContent(name: "file")]
public Stream Stream { get; set; }
[RESTFulStringContent(name: "purpose")]
public string Purpose { get; set; }
[RESTFulFileName(name: "file")]
public string FileName { get; set; }
}
// ...
var formUpload = new FormUpload
{
Stream = GetStream(),
Purpose = "fine-tune",
FileName = "SomeFile.jsonl"
};
var result = await PostFormAsync<FormUpload, ResultType>("https://example.com/upload", formUpload);
Note the linking of the FileName to the StreamContent via the name parameter in the attributes.
RESTFulSense uses by default NewtonSoft serialization/deserialization support. However, in some scenarios this could present some drawbacks. Imagine:
Here we have an example for a POST using System.Text.Json.JsonSerializer:
private readonly var jsonSerializerOptions =
new JsonSerializerOptions
{
// ...
};
private async ValueTask<string> Serialize<TContent>(TContent requestToSerialize)
{
using var memoryStream = new MemoryStream();
await JsonSerializer.SerializeAsync(memoryStream, requestToSerialize, jsonSerializerOptions);
using var streamReader = new StreamReader(memoryStream, Encoding.UTF8);
memoryStream.Position = 0;
return streamReader.ReadToEnd();
}
private async ValueTask<TResult> Deserialize<TResult>(string responseToDeserialize)
{
byte[] responseBytes = Encoding.UTF8.GetBytes(responseToDeserialize);
using var memoryStream = new MemoryStream(responseBytes);
var responseObject =
await JsonSerializer.DeserializeAsync<TResult>(memoryStream, jsonSerializerOptions);
return responseObject;
}
var result =
await restfulApiClient.PostContentAsync<Student>(
relativeUrl: "api/students",
content: inputStudent,
cancellationToken,
mediaType: "text/json",
ignoreDefaultValues: false,
serializationFunction: Serialize<TContent>,
deserializationFuntion: Deserialize<TResult>);
RESTFulSense provides an interface to the API client class, to make it easier to mock and leverage dependency injection for the testability of the client consumers, here's an example:
var restfulApiClientMock = new Mock<IRestfulApiClient>();
restfulApiClient.Setup(client =>
client.GetContentAsync<Student>(relativeUrl: $"api/students/{studentId}")
.ReturnsAsync(student);
If you have any suggestions, comments or questions, please feel free to contact me on:
This library is a community effort.
Huge thanks to Mr. Brian Parker @BrianLParker for his RESTfulSense Web Assembly effort.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on RESTFulSense:
| Package | Downloads |
|---|---|
|
Standard.AI.OpenAI
A Standardized .NET library for OpenAI Integrations. |
|
|
ISL.Providers.ReIdentification.Necs
ISL.Providers.ReIdentification.Necs provides a re-identification implementation the NECS Api. |
|
|
EventHighway
Standard-Compliant Open-Source Pub/Sub .NET library for managing events in distributed systems. |
|
|
ISL.Providers.Captcha.GoogleReCaptcha
ISL.Providers.Captcha.GoogleReCaptcha provides a provider wrapper implementation of the Google ReCaptcha service. |
|
|
ISL.Providers.Captcha.FakeCaptcha
ISL.Providers.Captcha.FakeCaptcha provides a fake implementation for testing purposes. |
Showing the top 2 popular GitHub repositories that depend on RESTFulSense:
| Repository | Stars |
|---|---|
|
hassanhabib/OtripleS
This is an open source schooling system, dedicated to provide a better experience for schools needing a management and communication and tutoring system all in one place. This project is aiming toward directing all the software development funds and hours to families in need, the idea of the project is to allow schools to use the system as long as the software funds in the school are directed towards financially disadvantaged families and students.
|
|
|
hassanhabib/Standard.AI.OpenAI
Standard-Compliant .NET library for Open AI
|
| Version | Downloads | Last Updated |
|---|---|---|
| 3.2.0 | 72,435 | 4/28/2025 |
| 3.1.0 | 97,688 | 9/19/2024 |
| 3.0.0 | 24,550 | 5/20/2024 |
| 2.20.0 | 20,822 | 5/2/2024 |
| 2.19.0 | 633 | 4/28/2024 |
| 2.18.0 | 4,487 | 4/1/2024 |
| 2.17.0 | 20,097 | 1/14/2024 |
| 2.16.0 | 13,731 | 12/30/2023 |
| 2.15.0 | 65,582 | 5/5/2023 |
| 2.14.0 | 367 | 5/4/2023 |
| 2.13.0 | 126,005 | 3/30/2023 |
| 2.12.0 | 9,863 | 3/24/2023 |
| 2.11.0 | 2,692 | 3/19/2023 |
| 2.10.0 | 2,093 | 3/14/2023 |
| 2.9.0 | 31,748 | 9/28/2022 |
| 2.8.0 | 4,833 | 8/29/2022 |
| 2.7.0 | 2,667 | 7/26/2022 |
| 2.6.0 | 1,963 | 7/13/2022 |
| 2.5.0 | 4,345 | 6/13/2022 |
| 2.4.0 | 24,608 | 11/11/2021 |
ActionResult Extensions For Comparisons