{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • Edge/API Management /
avatar image
0

How to Redirect an HTTP Request with the Payload Body  

  • Export to PDF
Imesh Gunaratne created · Feb 09 at 07:41 AM · 28 Views

In some scenarios API proxies may require to redirect incoming requests to a different target server with the same request payload. In such scenarios, we could use an AssignMessage policy similar to following for redirecting an HTTP request received by an API proxy to a different endpoint including the HTTP body:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Set-Response-Message">
    <DisplayName>Set-Response-Message</DisplayName>
    <Properties/>
    <Copy source="request">
        <Headers/>
        <QueryParams/>
        <FormParams/>
        <Payload/>
    </Copy>
    <Set>
        <StatusCode>301</StatusCode>
        <Headers>
            <Header name="Location">
                https://httpbin.org/post
            </Header>
        </Headers>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

Above AssignMessage policy could be engaged in the response flow as follows:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <PreFlow name="PreFlow">
        <Request/>
        <Response>
            <Step>
                <Name>Set-Response-Message</Name>
            </Step>
        </Response>
    </PreFlow>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPProxyConnection>
        <BasePath>/hello-redirect</BasePath>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="noroute"/>
</ProxyEndpoint>

An example API request and output:

curl -i --post301 -L -d "param1=value1" https://${org}-${env}.apigee.net/hello-redirect

HTTP/1.1 301 Moved Permanently
Date: Tue, 09 Feb 2021 07:26:03 GMT
Content-Type: application/x-www-form-urlencoded
Content-Length: 13
Connection: keep-alive
Host: imesh-eval-test.apigee.net
X-Forwarded-For: ---masked---
X-Forwarded-Port: 443
X-Forwarded-Proto: https
User-Agent: curl/7.64.1
Accept: */*
Location: https://httpbin.org/post

HTTP/2 200
date: Tue, 09 Feb 2021 07:26:04 GMT
content-type: application/json
content-length: 433
server: gunicorn/19.9.0
access-control-allow-origin: *
access-control-allow-credentials: true
{
"args": {},
"data": "",
"files": {},
"form": {
"param1": "value1"
},
"headers": {
"Accept": "*/*",
"Content-Length": "13",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "curl/7.64.1",
"X-Amzn-Trace-Id": "Root=---masked---"
},
"json": null,
"origin": "---masked---",
"url": "https://httpbin.org/post"
}


Please note that in this example I have set the redirection URL to https://httpbin.org/post and it is a public endpoint available on the Internet. If you are trying this example please change that to a known target server URL as that endpoint will receive the data being posted in the request.

thub.nodes.view.add-new-comment
apihttpredirection
Add comment
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Article

Contributors

avatar image

Follow this article

73 People are following this .

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Navigation

How to Redirect an HTTP Request with the Payload Body

Related Articles

Apigee Edge - 4MV4D - Quota Policy - Conditional Quota Count - S02E09

Apigee Edge - 4MV4D - Quota Policy - Flow Variables - S02E10

Apigee Edge - 4MV4D - Quota Policy - Error Handling - Fault Variables - S02E11

Api2Swagger : Open API (Swagger) 2.0 Spec Generator - Command line tool

Apigee 4MV4D - API Traffic Management : Quota - Series

Apigee 4MV4D - API Traffic Management : Quota - Series - Introduction to API Traffic Management - S02E01

Asynchronous HTTP Requests in an API proxy

Apigee 4MV4D - API Traffic Management : Quota - Series - Quota Policy - S02E02

Apigee Edge - 4MV4D - Quota Policy - Distributed & Synchronous - S02E03

Apigee Edge - 4MV4D - Quota Policy - Message Weight - S02E05

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges