Skip to content

Migration Guide

Alexander Klee edited this page Oct 15, 2021 · 6 revisions

Migrating to v1

Updating to v1 might break existing code.

PR #50, PR #54 and PR #59 introduced important changes to the API. Two new services IHealthService and IMetricsService have been added and related methods on IBlockfrostService have been extracted into these interfaces. See Appendix A for an overview of the affected methods.

Additionally outdated model and service classes have been removed. Please review your existing implementations and update your source code to use the new Service Interfaces (pluralized service names).

New Service Naming Conventions

To reflect the blockfrost.io OpenApi Specification more closely, a new set of Models and Service interfaces have been introduced.

Pluralized Service Name
// old
public partial class AccountService : IAccountService { }

// new 
public partial class AccountsService : IAccountsService { 
    public IHealthService Health { get; set; }
    public IMetricsService Metrics { get; set; }
}
Clearer Method Signatures

Method signatures on the old services have been inferred from the API operations return types, leading to ambiguity (i.e. IAccountService.Delegations2Async): Method signatures on the new services are inferred from the API endpoint's path:

// Endpoint: /accounts/{stake_address}/addresses 

// old 
Task<ICollection<StakeAddressesAddressesResponse>> AddressesAllAsync(string stake_address, int? count, int? page, ESortOrder? order);

// new 
Task<AccountAddressesContentResponseCollection> GetAddressesAsync(string stake_address, int? count, int? page, ESortOrder? order);

// the return type derives Collection>T> of the response content's item schema
public partial class AccountAddressesContentResponseCollection : Collection<AccountAddressesContentResponse> { }

Please update your code accordingly.

Appendix A

Old IBlockfrostService

In v1, every method has cancellation support.

public partial interface IBlockfrostService
{
    string Network { get; }

    Task<InfoResponse> GetInfoAsync(); 
    Task<ClockResponse> GetClockAsync();
    Task<HealthResponse> GetHealthAsync();
    Task<ICollection<MetricResponse>> GetMetricsAsync();
    Task<ICollection<MetricsEndpointResponse>> EndpointsAsync();
}

New interfaces in V1

interface IHealthService
{
    Task<ApiInfoResponse> GetApiInfoAsync(); 
    Task<HealthResponse> GetHealthAsync();
    Task<HealthClockResponse> GetHealthClockAsync();
}

interface IMetricsService
{
    Task<MetricsResponseCollection> GetMetricsAsync();
    Task<MetricsEndpointsResponseCollection> GetEndpointsAsync();
}

interface IBlockfrostService
{
    string Network { get; set; }
    string BaseUrl { get; set; }
    bool ReadResponseAsString { get; set; }
}