NHSDigital.ApiPlatform.Sdk
0.2.0.1
dotnet add package NHSDigital.ApiPlatform.Sdk --version 0.2.0.1
NuGet\Install-Package NHSDigital.ApiPlatform.Sdk -Version 0.2.0.1
<PackageReference Include="NHSDigital.ApiPlatform.Sdk" Version="0.2.0.1" />
<PackageVersion Include="NHSDigital.ApiPlatform.Sdk" Version="0.2.0.1" />
<PackageReference Include="NHSDigital.ApiPlatform.Sdk" />
paket add NHSDigital.ApiPlatform.Sdk --version 0.2.0.1
#r "nuget: NHSDigital.ApiPlatform.Sdk, 0.2.0.1"
#:package NHSDigital.ApiPlatform.Sdk@0.2.0.1
#addin nuget:?package=NHSDigital.ApiPlatform.Sdk&version=0.2.0.1
#tool nuget:?package=NHSDigital.ApiPlatform.Sdk&version=0.2.0.1
NHSDigital.ApiPlatform.Sdk (Core)
Overview
NHSDigital.ApiPlatform.Sdk is a host-agnostic .NET SDK that wraps the NHS Digital API Platform:
Currently support includes:
- CIS2 Authentication (Authorization Code Flow)
- PDS FHIR R4 client (example implementation)
(Future extensibility for additional NHS Digital APIs is planned.)
This package does not depend on ASP.NET Core. You must provide implementations of token and state storage interfaces, allowing the SDK to work in any .NET host environment.
Installation
dotnet add package NHSDigital.ApiPlatform.Sdk
Configuration
The SDK is configured via ApiPlatformConfigurations:
using NHSDigital.ApiPlatform.Sdk.Models.Configurations;
var config = new ApiPlatformConfigurations
{
CareIdentity = new CareIdentityConfigurations
{
ClientId = "...",
ClientSecret = "...",
RedirectUri = "...",
AuthEndpoint = "...",
TokenEndpoint = "...",
UserInfoEndpoint = "...",
AcrValues = "aal3" // optional
},
PersonalDemographicsService = new PersonalDemographicsServiceConfigurations
{
BaseUrl = "https://.../personal-demographics/FHIR/R4"
}
};
Storage Abstractions
The SDK relies on two storage abstractions:
IApiPlatformStateBroker(CSRF state for the login flow)IApiPlatformTokenBroker(access/refresh tokens and expiry timestamps)
Default Implementations (In-Memory)
The Core SDK includes optional in-memory implementations:
MemoryApiPlatformStateBrokerMemoryApiPlatformTokenBroker
These are suitable for:
- Development
- Prototypes
- Console applications / single-user processes
For production web applications, prefer a host-appropriate implementation (e.g., session, distributed cache, or database-backed storage). The ASP.NET Core package provides web-specific implementations.
🚀 Quick Start - Registration (DI)
Register the core services:
using NHSDigital.ApiPlatform.Sdk;
services.AddApiPlatformSdkCore(config);
If you are running outside ASP.NET Core and want the in-memory defaults:
services.AddApiPlatformSdkCore(config);
services.AddApiPlatformSdkInMemoryStorage();
Production storage (non in-memory)
If you do not use the in-memory defaults, register your own implementations of:
- IApiPlatformStateBroker
- IApiPlatformTokenBroker
Example: register custom production-ready brokers (database, distributed cache, key vault, etc.):
using NHSDigital.ApiPlatform.Sdk;
using NHSDigital.ApiPlatform.Sdk.Brokers.Storages;
// Your implementations (examples)
services.AddSingleton<IApiPlatformStateBroker, MyProductionApiPlatformStateBroker>();
services.AddSingleton<IApiPlatformTokenBroker, MyProductionApiPlatformTokenBroker>();
services.AddApiPlatformSdkCore(config);
ASP.NET Core applications should use the
NHSDigital.ApiPlatform.Sdk.AspNetCorepackage to register web-specific storage. NHSDigital.ApiPlatform.Sdk.AspNetCore README
🚀 Quick Start (No DI)
For simple hosts, you can instantiate the root client directly:
using NHSDigital.ApiPlatform.Sdk.Clients.ApiPlatforms;
IApiPlatformClient apiPlatformClient = new ApiPlatformClient(config);
This constructor wires up the SDK internally and uses in-memory storage defaults.
Using Custom Storage (No DI)
If you want to provide production-ready storage implementations (for example, database-backed or distributed cache), use the static Create method:
using NHSDigital.ApiPlatform.Sdk.Clients.ApiPlatforms;
using NHSDigital.ApiPlatform.Sdk.Brokers.Storages;
IApiPlatformStateBroker stateBroker = new MyProductionStateBroker();
IApiPlatformTokenBroker tokenBroker = new MyProductionTokenBroker();
IApiPlatformClient apiPlatformClient =
ApiPlatformClient.Create(config, stateBroker, tokenBroker);
ApiPlatformClient.Create(config, stateBroker, tokenBroker);
If either broker is omitted (or passed as null), the SDK will automatically fall back to the built-in in-memory implementations.
The Create method is intended for non-DI scenarios. ASP.NET Core applications should use the DI registration approach instead. NHSDigital.ApiPlatform.Sdk.AspNetCore README
Using the SDK
Start Login
string loginUrl = await apiPlatformClient
.CareIdentityServiceClient
.BuildLoginUrlAsync(cancellationToken);
return Redirect(loginUrl);
Handle Callback and Retrieve User Info
Use the processing-based convenience method which completes the callback flow and returns user information:
var userInfo = await apiPlatformClient
.CareIdentityServiceClient
.GetUserInfoAsync(code, state, cancellationToken);
This call:
- Validates
codeandstate - Exchanges the authorization code for tokens
- Stores access and refresh tokens
- Retrieves user information
Retrieve an Access Token (Auto Refresh Enabled)
string accessToken = await apiPlatformClient
.CareIdentityServiceClient
.GetAccessTokenAsync(cancellationToken);
If the access token is expired or expiring within the next 60 seconds, the SDK will refresh it using the refresh token, store the new tokens, and return the refreshed access token.
Search Patients
string responseJson = await apiPlatformClient
.PersonalDemographicsServiceClient
.SearchPatientsAsync(
family: "Smith",
given: new[] { "John" },
gender: "male",
birthdate: new DateOnly(1980, 1, 1),
cancellationToken: cancellationToken);
© North East London ICB
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- ISL.Providers.PDS.Abstractions (>= 1.0.0.8)
- ISL.Providers.PDS.FakeFHIR (>= 1.0.0.8)
- ISL.Providers.PDS.FHIR (>= 1.0.0.8)
- Microsoft.Extensions.DependencyInjection (>= 10.0.3)
- Microsoft.Extensions.Http (>= 10.0.3)
- Xeption (>= 2.8.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on NHSDigital.ApiPlatform.Sdk:
| Package | Downloads |
|---|---|
|
NHSDigital.ApiPlatform.Sdk.AspNetCore
NHS Digital API Platform Client. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.2.0.1 | 78 | 3/23/2026 |
Initial release of the NHS Digital API Platform Client.