HTTP Redirect

Overview

Use this policy to manage HTTP redirection for API requests. When an HTTP response status is returned with a 3xx HTTP status code, the client side handles the redirect as defined in the policy.

Policy Execution Order

Transformation of request headers works in the following policy sequence for both APIs and Proxies:
Authorize By Role ➡️ Authentication Policy ➡️ Traffic Policy ➡️ HTTP Redirect

Expression Enabled Fields in API Policies

All expression-enabled fields take expressions from the SnapLogic Expression Language and the API Policy Manager functions.

Architecture

For this article, the client side is called the user-agent. For APIM, the user-agent might be a web browser, HTTP client, or cURL application. Since the user-agent is responsible for handling the response, the policy assumes that the user-agent (and not the server) performs the redirects; this includes processing follow-on HTTP methods, payload content, and redirect addresses. The server (Snaplex) is only responsible for setting the Response status type, status code, location header, and, where defined, the message content.

Limitations

Only message bodies for application/json and application/xml content types are validated by the UI.

Settings

Parameter Name

Description

Default Value

Parameter Name

Description

Default Value

Label

Required. The name for the API policy.

HTTP Redirect

When this policy should be applied

An expression enabled field that determines the condition to be fulfilled for the API policy to execute.

For example, if the value in this field is request.method == "POST", the API policy is executed only if the request method is a POST.

N/A

HTTP Redirect Properties

The controls for HTTP redirection. Click to add redirect properties to the policy. Each property defines a condition to return a HTTP redirect response. Each property also include fields for specifying the redirect URL, content-type, and message body for the HTTP response. To remove the redirect property, click - and click Validate and Save.

N/A

Use User-Agent Content

Select this checkbox to redirect an HTTP user-agent with the user-agent’s original request contents, such as the content type, message body, and query parameters.

Note: Deselecting this checkbox does not remove the redirect property.

N/A

Condition*

Enter an expression to prompt an HTTP redirect when it evaluates to True. An expression that evaluates to False will not prompt an HTTP redirect response.

N/A

Response Status*

Select one of the following:

  • 300 - Multiple Choices. The request has more than one possible response. The user agent or user should choose one of them. (There is no standardized way of choosing one of the responses, but HTML links to the possibilities are recommended so the user can pick.)

  • 301 - Moved Permanently. The URL of the requested resource has been changed permanently. The new URL is given in the response.

  • 302 - Found. This response code means that the URI of requested resource has been changed temporarily. Further changes in the URI might be made in the future. Therefore, this same URI should be used by the client in future requests.

  • 303 - See Other. This is used for caching purposes. It tells the client that the response has not been modified, so the client can continue to use the same cached version of the response.

  • 307 - Temporary Redirect. The server sends this response to direct the client to get the requested resource at another URI with the same method that was used in the prior request. This has the same semantics as the 302 Found HTTP response code, with the exception that the user agent must not change the HTTP method used: if a POST was used in the first request, a POST must be used in the second request.

  • 308 - Permanant Redirect. This means that the resource is now permanently located at another URI, specified by the Location: HTTP Response header. This has the same semantics as the 301 Moved Permanently HTTP response code, with the exception that the user agent must not change the HTTP method used: if a POST was used in the first request, a POST must be used in the second request.

N/A

Redirect URL

Click to specify an expression to build a valid URL.

Note: Some functions in the dropdown list might not be applicable and therefore will not work.

Alternatively, you can disable the Expression field to enter the URL for the redirection. Example: https://docs-snaplogic.atlassian.net/wiki/search?text=client

N/A

Content-Type

Click to specify a function. For expressions containing a semi-colon (;), you can use escape() to allow the expression to compile. For example: escape("text/xml; charset=utf-8")

You can add other content types recognized by IANA, such as:
application/alto-error+json escape("application/alto-error+json; charset=windows-1252")

Note: Some functions in the dropdown list might not be applicable and therefore will not work.

Alternatively, select the content type from the dropdown:

  • application/json.

  • application/xml.

  • text/html.

  • text/plain.

  • text/xml.

N/A

Message Body

Enter a message for the API caller.

Example:

{ "Hello":"World" }

N/A

Status

Specifies whether the API policy is enabled or disabled. 

Enabled