ServiceApiClient class provides an interface to fetch service details from the GOV.UK Notify API, used to display service names and contact information on document download pages.
Class Overview
ServiceApiClient
API client wrapper around NotificationsAPIClient configured for service data retrieval. Location:app/notify_client/service_api_client.py
Initialization
__init__
Creates a configured ServiceApiClient instance.Flask application instance with configuration
API_HOST_NAME: Base URL for Notify APIADMIN_CLIENT_USER_NAME: Client username (service ID)ADMIN_CLIENT_SECRET: Client secret for authentication
The client uses a placeholder API key during initialization because credential lengths don’t match what
NotificationsAPIClient.__init__ expects. Actual credentials are set directly after initialization.Methods
get_service
Retrieves service information by service ID.Service identifier (UUID or string)
Service data from API
- Raises
HTTPErrorfromnotifications_python_clienton API errors - Caller should catch and handle errors appropriately (see view functions)
OnwardsRequestNotificationsAPIClient
Internal client class that extendsNotificationsAPIClient with request header forwarding.
generate_headers
Generates HTTP headers including authentication and request forwarding.API authentication token
HTTP headers for API request
- Calls parent
NotificationsAPIClient.generate_headers()for authentication - Merges onwards request headers if in request context
- Returns combined headers dictionary
X-Request-ID: Request tracking identifierX-B3-TraceId,X-B3-SpanId: Distributed tracing headers- Other monitoring/debugging headers
Global Instance
The application provides a thread-safe global instance accessible fromapp:
service_api_client is implemented using ContextVar and LocalProxy:
- Each request gets its own client instance
- No state leakage between concurrent requests
- Lazy initialization only when needed
Configuration Reference
See Configuration Classes for environment variable setup:API_HOST_NAMEADMIN_CLIENT_USER_NAMEADMIN_CLIENT_SECRET
Related Documentation
- View Functions - Usage in route handlers
- Application Initialization - Client setup and lifecycle