From 51ec30a74373f9583d3fe99984bc95f38f05f51a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fulcan=20TURAN?= Date: Sun, 23 Jul 2023 14:54:18 +0200 Subject: [PATCH] Update README.md --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7c0c278..e224dfc 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## Introduction -Provides a generic response type compatible with `IActionResult` in `Microsoft.AspNetCore.Mvc`. This library is designed to simplify API responses by offering a structured model that can contain data, errors, validation errors, and additional extensions. +Provides a generic response type (`IResponse`) compatible with `IActionResult` in `Microsoft.AspNetCore.Mvc`. This library is designed to simplify API responses by offering a structured model that can contain data, errors, validation errors, and additional extensions. ## Features @@ -26,11 +26,56 @@ dotnet add package Ogu.AspNetCore.Response.Json **example 1:** ```csharp - +public IActionResult GetExample1() +{ + return HttpStatusCode.OK.ToSuccessResponse(new string[]{ "Freezing", "Bracing", "Chilly" }); +} ``` output ```bash +{ + "data": [ + "Freezing", + "Bracing", + "Chilly" + ], + "success": true, + "status": 200 +} +``` +**example 2:** +```csharp +public IActionResult GetExample2() +{ + return HttpStatusCode.OK.ToFailResponse(ErrorKind.EXAMPLE_ERROR_OCCURRED); +} ``` + +output + +```bash +{ + "success": false, + "status": 200, + "result": { + "title": "Bad Request", + "status": 400, + "detail": "Custom failure occurred.", + "extensions": { + "errors": [ + { + "title": "EXAMPLE_ERROR_OCCURRED", + "description": "Don't worry, everything's gonna be alright", + "code": "0", + "type": 0 + } + ] + } + } +} +``` + +**sample app:** [Sample.Api](https://github.com/ogulcanturan/Ogu.AspNetCore.Response/tree/master/samples/Sample.Api)