search

How to Obtain the Accept-Language HTTP Header With IBM API Management


In this post I am going to explain how you obtain the client side HTTP Accept-Language setting for APIs built with IBM API Management on Bluemix and use the setting to determine the appropriate language to use in your API. I have created some sample code on IBM Jazz Hub that you can use as a basis for adding this capability to your own APIs.

When you are designing globalized APIs that are deployed using IBM API Management you need to take a few specific actions during the assembly step to ensure that the HTTP Accept-Language header field is properly forwarded to your implementing API.

By default IBM API Management does not forward and map all HTTP header fields to your underlying implementing API. To forward the Accept-Language field from the HTTP header perform the following steps:

  1. From the Overview tab select Request from the left navigation and then add the Accept-Language field from the available HTTP header fields.

    Select Accept-Language

    Select Accept-Language

  2. From the Implementation tab establish a connection to your underlying implementing API.

    Establish API Connection

    Establish API Connection

  3. From the Define tab under Request Headers select Accept-Language.

    Select Accept-Language Field

    Select Accept-Language Field

  4. Frome the Configure tab select Select Values and then select the Accept-Language field to map the value to your underlying API implementation. After you complete this step you will be able to access the Accept-Language setting from your API.

    Map Accept-Language HTTP Header Field

    Map Accept-Language HTTP Header Field

Once you have the Accept-Language field being forwarded to your API you can compare that value with all the supported languages in your service. To help make the task of selecting the most appropriate language to use in your service you can use the accept-language Node.js package. In my example service I support three languages: English (en), French (fr), and Spanish (es) with the default being set to English.

I hope this helps you get started building globalized APIs with IBM API Management on Bluemix.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

close
search
Latest Tweets

Hi, guest!

settings

menu