CrossCutting.ApiHandler 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CrossCutting.ApiHandler --version 1.0.0
NuGet\Install-Package CrossCutting.ApiHandler -Version 1.0.0
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="CrossCutting.ApiHandler" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CrossCutting.ApiHandler --version 1.0.0
#r "nuget: CrossCutting.ApiHandler, 1.0.0"
#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.
// Install CrossCutting.ApiHandler as a Cake Addin
#addin nuget:?package=CrossCutting.ApiHandler&version=1.0.0

// Install CrossCutting.ApiHandler as a Cake Tool
#tool nuget:?package=CrossCutting.ApiHandler&version=1.0.0

CrossCutting ApiHandler Documentação

Primeiro para usar o ApiHandler você deve inicia-lo com um dos dois construtores :

Primeiro construtor quando a chamada não é autenticada:

public Handler(string baseUrl) : this() { _baseUrl = baseUrl; UrlAuth = string.Format("{0}{1}", baseUrl, "/oauth2/token"); }

A baseUrl deve ser a url base que será usada nas requisições http da sua api, exemplo:

var handler = new Handler("https://suaapi");

Segundo construtor quando a chamada é autenticada:

public Handler(string baseUrl, List<Parameters> authorizationParams) : this(baseUrl) { AuthorizationParams = authorizationParams; listKeyValues = AuthorizationParams.ListKeyValues(); }

A baseUrl deve ser a url base que será usada nas requisições http da sua api, os parametros são os parametros passados para sua autenticação JWT Bearer, exemplo:

var handler = new Handler("https://suaapi", new List<Parameters> { new Parameters("UserName", ""), new Parameters("Password", ""), new Parameters("client_Id", ""), new Parameters("client_secret", "");

Você pode iniciar o construtor via injeção de dependência também caso queira chamá-lo apenas uma vez, exemplo:

public class suaClasse : Handler, IsuaClasse { public suaClasse() : base("https://suaapi", new List<Parameters> { new Parameters("UserName", ""), new Parameters("Password", ""), new Parameters("client_Id", ""), new Parameters("client_secret", "") }) {

}

}

Após isso é só registrar no container da sua injeção de dependência, nesse exemplo usando simple injector:

container.Register<IsuaClasse, suaClasse>();

Após iniciar o construtor a chamada da api e simples:

POST: - Sem parâmetros na URL: var result = handler.Post<Obj>("/exemplo/key", Obj);

- Com parêmetros na URL:
 var result = handler.Post<Obj>("/Usuario/Id", new List<Parameters> {
            new Parameters("exemplo","1"),
			new Parameters("exemplo2","2")
        }, Obj);

GET: - Sem parêmtros na URL: var result = handler.GetAsString("/exemplo/key");

-Com parâmetros na URL:
var result = handler.GetAsString("/exemplo/key", new List<Parameters> {
            new Parameters("exemplo","1"),
			new Parameters("exemplo2","2")
        });
Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0.2 1,052 12/14/2018
1.0.1 726 11/19/2018
1.0.0 955 11/8/2018