All Projects → hassanhabib → Restfulsense

hassanhabib / Restfulsense

A RESTFul operations client that serializes responses and throws meaningful exceptions for >= 400 status codes.

Programming Languages

csharp
926 projects

Projects that are alternatives of or similar to Restfulsense

awesome-dotnet-async
A curated list of awesome articles and resources to learning and practicing about async, threading, and channels in .Net platform. 😉
Stars: ✭ 84 (+200%)
Mutual labels:  dotnetcore, netcore, asp-net-core
AvroConvert
Apache Avro serializer for .NET
Stars: ✭ 44 (+57.14%)
Mutual labels:  serialization, deserialization, netcore
Awesome-Nuget-Packages
📦 A collection of awesome and top .NET packages sorted by most popular needs.
Stars: ✭ 87 (+210.71%)
Mutual labels:  dotnetcore, netcore, asp-net-core
Simplcommerce
A simple, cross platform, modularized ecommerce system built on .NET Core
Stars: ✭ 3,474 (+12307.14%)
Mutual labels:  asp-net-core, dotnetcore, netcore
Ysoserial
A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.
Stars: ✭ 4,808 (+17071.43%)
Mutual labels:  serialization, deserialization
Typesystem
Data validation, serialization, deserialization & form rendering. 🔢
Stars: ✭ 416 (+1385.71%)
Mutual labels:  serialization, deserialization
Awesome Microservices Netcore
💎 A collection of awesome training series, articles, videos, books, courses, sample projects, and tools for Microservices in .NET Core
Stars: ✭ 865 (+2989.29%)
Mutual labels:  asp-net-core, dotnetcore
Fastjson
A fast JSON parser/generator for Java.
Stars: ✭ 23,997 (+85603.57%)
Mutual labels:  serialization, deserialization
Handyjson
A handy swift json-object serialization/deserialization library
Stars: ✭ 3,913 (+13875%)
Mutual labels:  serialization, deserialization
Netcorebbs
ASP.NET Core Light forum NETCoreBBS
Stars: ✭ 483 (+1625%)
Mutual labels:  asp-net-core, netcore
Fasteasymapping
A tool for fast serializing & deserializing of JSON
Stars: ✭ 556 (+1885.71%)
Mutual labels:  serialization, deserialization
Colander
A serialization/deserialization/validation library for strings, mappings and lists.
Stars: ✭ 408 (+1357.14%)
Mutual labels:  serialization, deserialization
Networker
A simple to use TCP and UDP networking library for .NET. Compatible with Unity.
Stars: ✭ 408 (+1357.14%)
Mutual labels:  dotnetcore, netcore
Quick Xml
Rust high performance xml reader and writer
Stars: ✭ 480 (+1614.29%)
Mutual labels:  serialization, deserialization
Module Shop
一个基于 .NET Core构建的简单、跨平台、模块化的商城系统
Stars: ✭ 398 (+1321.43%)
Mutual labels:  dotnetcore, netcore
Cista
Simple C++ Serialization & Reflection.
Stars: ✭ 535 (+1810.71%)
Mutual labels:  serialization, deserialization
Bluecap
iOS Bluetooth LE framework
Stars: ✭ 669 (+2289.29%)
Mutual labels:  serialization, deserialization
Marshmallow
A lightweight library for converting complex objects to and from simple Python datatypes.
Stars: ✭ 5,857 (+20817.86%)
Mutual labels:  serialization, deserialization
Iod
Meta programming utilities for C++14. Merged in matt-42/lithium
Stars: ✭ 731 (+2510.71%)
Mutual labels:  serialization, deserialization
Jackson Module Kotlin
Module that adds support for serialization/deserialization of Kotlin (http://kotlinlang.org) classes and data classes.
Stars: ✭ 830 (+2864.29%)
Mutual labels:  serialization, deserialization

RESTFulSense

I designed & developed this library as a wrapper around the existing .NET Core HttpClient implementation to provide the following values:

  1. Meaningful Exceptions for APIs response status codes.
  2. Simplified API communications.
  3. Test-friendly implementation.

You can get RESTFulSense Nuget package by typing:

Install-Package RESTFulSense

Here's the details of what this library has to offer:

1. Meaningful Exceptions

RESTFulSense provide the following exceptions for erroring HTTP Status Codes as follows:

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

2. Simplified API communications

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:

2.1 On Controller Level

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.

2.2 On Consumer Level

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:

2.2.1 Initialization

The initialization of the RESTFulSense Client can be done in two different ways:

2.2.1.1 HttpClientFactory Approach

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));

2.2.1.2 Basic Initialization

You can also use the RESTFulClient simple initialize in a console app for instance as follows:

var apiClient = new RESTFulApiClient();

2.2.1 Deserialization
List<Student> students = 
    await restfulApiClient.GetContentAsync<List<Student>>(relativeUrl: "api/students");

2.2.2 Serialization
Student student = 
    await restfulApiClient.PostContentAsync<Student>(relativeUrl: "api/students", content: inputStudent); 

In addition to the wrappers around API calls and serialziation/deserialization, this library alos 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");

3. Testing-Friendly Implementation

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:
Twitter: @hassanrezkhabib
LinkedIn: hassanrezkhabib
E-Mail: [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].