DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Python Techniques for Text Extraction From Images
  • OneStream Fast Data Extracts APIs
  • Reversing an Array: An Exploration of Array Manipulation
  • Setup ActiveMQ Artemis on Windows

Trending

  • My LLM Journey as a Software Engineer Exploring a New Domain
  • Breaking Bottlenecks: Applying the Theory of Constraints to Software Development
  • Hybrid Cloud vs Multi-Cloud: Choosing the Right Strategy for AI Scalability and Security
  • AI’s Role in Everyday Development

Apigee: Extract The Header's Content

Let's take a look at extracting the header's content using Apigee. Let's also explore the Assign Message policy.

By 
Prashant Sharma user avatar
Prashant Sharma
·
Updated Sep. 05, 18 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
9.0K Views

Join the DZone community and get the full member experience.

Join For Free

This article was first published on the Knoldus blog.

Hello everyone, in my previous article, we saw how various Policies in Apigee make our life easy and our API faster and valuable. We saw Response Cache, Extract Variable, and Spike Arrest policy in action. If you want to go through the basics of Apigee or want to brush up your understanding of the Apigee policies, you can visit:

Basics of APIGEE and Understanding the Policies

Recently, while working on one of my projects, I came across a scenario where I was required to extract a header through APIGEE and save that header value in some other header combined with a timestamp so that this new header becomes a key for caching in Apigee. There was a collection of comma-separated names in the header and I was required to save them all in my new header along with the timestamp.

The most straightforward approach to this could be I supply an Assign Message Policy to my API proxy flow and in it, I extract out the content of my header add the timestamp to it and save it to a new header. Later in the Response Cache Policy, I set this new header as my key.

Let's see how this works out:

  1. Create assign message policy to extract out Header and add the timestamp value to it, set this new value into a new header.
  2. Create response cache policy to set this new header as a key.

The Assign Message policy would look like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage name="AccessRequest1">
 <DisplayName>AccessRequest1</DisplayName>
 <AssignTo createNew="false" type="request"/>
 <Set>
 <Headers>
<Header name="cacheKeyHeader">{request.header.user.values}{system.time}</Header>
</Headers>
</Set>
</AssignMessage>

and the Response Cache Policy would look like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ResponseCache async="false" continueOnError="false" enabled="true" name="ResponseCacheCacheHelloMessage">
 <DisplayName>ResponseCache.CacheHelloMessage</DisplayName>
 <CacheKey>
 <KeyFragment ref="request.uri" type="string"/>
 <KeyFragment ref="request.header.cacheKeyHeader.values" type="string"/>
 </CacheKey>
 <Scope>Application</Scope>
 <ExpirySettings>
 <TimeoutInSec ref="">60</TimeoutInSec>
 </ExpirySettings>
</ResponseCache>

So I have a header named user that was passed in the incoming request, which contains a list of comma-separated usernames. In the Assign message policy I extracted user's content and appended a timestamp to it, then I assigned this new value to a new header named cacheKeyHeader.

To extract out the exact value passed to the header user, I used "{request.header.user.values}" the ".values" takes care of the multiple comma-separated usernames that we passed in the header, if I had not used the ".values" then only the first name before the first comma(,) would have been fetched from the header.

Later on in the Response cache policy, I set the cacheKeyHeader's value as my cache key with the following segment of code:

  <KeyFragment ref="request.header.cacheKeyHeader.values" type="string"/>

So that is how we can Extract multiple comma-separated values out of a header in Apigee. For a sample hands-on with this scenario, one can clone in the APIProxy from here and then through Postman, you can try hitting my service endpoint.

Also, don't forget to pass on a header "user" to this endpoint through Postman. For example add Key = user and value = [user1,user2,user3] in the postman while hitting the above proxy endpoint.

The API proxy for the same can be found here.

Please feel free to comment or reach out to me in case of any queries.

This article was first published on the Knoldus blog.

Extract

Published at DZone with permission of Prashant Sharma, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Python Techniques for Text Extraction From Images
  • OneStream Fast Data Extracts APIs
  • Reversing an Array: An Exploration of Array Manipulation
  • Setup ActiveMQ Artemis on Windows

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: