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 Dp.Services.HTTP.DpGet command, allowing you to access an API from another microservice based on the Devprime platform and 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 offers 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 a result class based on the interface 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 into <T>
Get<T>(url,connection) Enter url, connection, and a class for automatic conversion to <T>
Get<T>(param) HTTPParameter parameter and a class for automatic conversion to <T>
Summary You can use any <T> class in Get
DpGet Used in Devprime-based urls
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 into <T>
DpGet<T>(url,connection) Enter url, connection, and a class for automatic conversion to <T>
DpGet<T>(param) HTTPParameter parameter and a class for automatic conversion to <T>
Summary The <T> class used in DpGet requires an IServicesResult

Explore implementation examples:


Last modified April 16, 2024 (2b35fcc8)