Services

The Devprime platform offers a Services adapter that simplifies connecting to external APIs through RPC, HTTP, gRPC, GraphQL, and supports automatic strategies for distributed systems such as Retry, Circuit-breaker, and resiliency.

This code example demonstrates how the Services Adapter simplifies access to external API’s using the command Dp.Services.HTTP.DpGet allowing you to access an API from another microservice based on the Devprime platform and already bring the typed return.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
public override dynamic Handle(DeliveryGetOrder domainEvent)
{
    // Aggregate Root
    var delivery = domainEvent.Get<Domain.Aggregates.Delivery.Delivery>();

    // URL de acesso externo
    var url = $"https://localhost:5001/v1/order/{delivery.OrderID}";

    // Executando o request externo usando http e 
    // conversão automática em OrderCreated.
    var result = Dp.Services.HTTP.DpGet<OrderCreated>(url);

    // Analisando o resultado da consulta externa se retorno 200 ou 201
    if (result.Dp.Status.Equals(200)|| result.Dp.Status.Equals(201))
        return result.Total; // Obtendo o resultado tipado
    else
        return null;
}

Services Adapter and Related Commands Dp.Services.HTTP

The Services Adapter on the Devprime platform provides a series of commands involving Post, Get, Put, Delete, Download, and specialized implementations that include methods starting with “Dp”, such as the DpGet method. In addition, these methods bring intelligent behaviors, such as an interface-based result class DevPrime.Stack.Foundation.Application.IServicesResult.

Dp.Services.HTTP
Get Using in external urls
Get(url) Enter the url as string
Get(url,connection) Enter the url as a string and a connection
Get(param) Include HTTPParameter
Get<T>(url) Enter the url and a class for automatic conversion in <T>
Get<T>(url,connection) Enter url, connection, and a class for automatic conversion in <T>
Get<T>(param) HTTPParameter parameter is a class for automatic conversion to <T>
Summary You can use any class <T> in Get
DpGet Used in urls based on Devprime
DpGet(url) Enter the url as string
DpGet(url,connection) Enter the url as a string and a connection
DpGet(param) Include HTTPParameter
DpGet<T>(url) Enter the url and a class for automatic conversion in <T>
DpGet<T>(url,connection) Enter url, connection, and a class for automatic conversion in <T>
DpGet<T>(param) HTTPParameter parameter is a class for automatic conversion to <T>
Summary The class <T> used in DpGet requires an IServicesResult

Explore implementation examples:


Last modified September 10, 2024 (6166aa4f)