sdk-middleware-user-agent

Middelware to automatically set the User-Agent to the request.

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.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)

  1. libraryName (String): the name of the library / package / application using the SDK (optional)
  2. libraryVersion (String): the version of the library / package / application using the SDK (optional)
  3. contactUrl (String): the contact URL of the library / package / application using the SDK (optional)
  4. 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)

results matching ""

    No results matching ""