context function
Middleware that adds platform context and API tokens to requests.
This middleware automatically adds:
- Platform information (iOS, Android, etc.) via X-Calljmp-Platform header
- Development API token if configured
config The Calljmp configuration containing platform and development settings.
Returns an HttpMiddleware function.
Example
final client = HttpClient(http.Client())
.use([context(config)]);
Implementation
HttpMiddleware context(Config config) =>
(http.BaseRequest request, next) async {
final values = await aggregateContext(config);
request.headers.addAll(values);
return next(request);
};