sdk-middleware-user-agent
Middleware to automatically set the User-Agent
to the request.
⚠️ In Maintenance Mode ⚠️
This package has been replaced by the TypeScript SDK is in maintenance mode as such this tool will no longer receive new features or bug fixes.
We recommend to use the TypeScript SDK for any new implementation and plan migrating to it.
Install
Node.js
npm install --save @commercetools/sdk-middleware-user-agent
Browser
<script src="https://unpkg.com/@commercetools/sdk-middleware-user-agent/dist/commercetools-sdk-middleware-user-agent.umd.min.js"></script>
<script>
// global: CommercetoolsSdkMiddlewareUserAgent
</script>
createUserAgentMiddleware(options)
Creates a middleware to append the User-Agent
HTTP header to the request.
Named arguments (options)
libraryName
(String): the name of the library / package / application using the SDK (optional)libraryVersion
(String): the version of the library / package / application using the SDK (optional)contactUrl
(String): the contact URL of the library / package / application using the SDK (optional)contactEmail
(String): the contact email of the library / package / application using the SDK (optional)
Usage example
import { createClient } from '@commercetools/sdk-client'
import { createUserAgentMiddleware } from '@commercetools/sdk-middleware-user-agent'
import { createAuthMiddleware } from '@commercetools/sdk-middleware-auth'
import { createHttpMiddleware } from '@commercetools/sdk-middleware-http'
const userAgentMiddleware = createUserAgentMiddleware(),
const client = createClient({
middlewares: [
createAuthMiddleware({...}),
createUserAgentMiddleware({
libraryName: 'my-awesome-library',
libraryVersion: '1.0.0',
contactUrl: 'https://github.com/commercetools/my-awesome-library'
contactEmail: 'helpdesk@commercetools.com'
}),
createHttpMiddleware({...}),
],
})
// The User-Agent will be something like:
// commercetools-js-sdk Node.js/6.9.0 (darwin; x64) my-awesome-library/1.0.0 (+https://github.com/commercetools/my-awesome-library; +helpdesk@commercetools.com)