-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add request redirection documentation
- Loading branch information
Showing
6 changed files
with
312 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
We support API management through a set of Custom Resources (CRs) that adhere to Kubernetes Gateway Specification. See [APK Kubernetes CRD Catalog]({{base_path}}/en/latest/catalogs/kubernetes-crds) for more information. | ||
|
||
Additionally, our REST API flow can generate a set of CRs based on the API definitions provided through OpenAPI Specifications, Service Description Languages (SDLs), and APK configuration files. This flow is designed to streamline the API development process and reduce the manual effort required to create basic API related CRs. Follow steps mentions in [Generate APK Configuration File]({{base_path}}/en/latest/api-management-overview/tools-for-api-development/#option-2-generate-k8s-custom-resources-using-config-generator-tool-and-deploy-the-api-using-kubernetes-client) to generate APK configuration files. | ||
Additionally, our REST API flow can generate a set of CRs based on the API definitions provided through OpenAPI Specifications, Service Description Languages (SDLs), and APK configuration files. This flow is designed to streamline the API development process and reduce the manual effort required to create basic API related CRs. Follow the steps mentioned in [Generate APK Configuration File]({{base_path}}/en/latest/api-management-overview/tools-for-api-development/#option-2-generate-k8s-custom-resources-using-config-generator-tool-and-deploy-the-api-using-kubernetes-client) to generate APK configuration files. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...te-and-attach-api-policies/redirect-request-filters/redirect-request-via-crs.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Request Redirection via REST API | ||
|
||
Request redirection allows you to send clients to a different URL. This can be useful for changing old URLs to new ones or directing traffic based on specific conditions. Request redirection can be configured via Kubernetes CRs as follows. | ||
|
||
### Step 1 - Get the CRs for the relevant API configuration | ||
|
||
Here, you can follow the steps in [Develop and Deploy a REST API via CRs](../../create-and-deploy-apis/rest/create-rest-api-using-crs.md) documentation and create the CRs to deploy an API from scratch. | ||
|
||
Alternatively, you can generate the CRs for a given apk-conf file using the steps as detailed in [this section]({{base_path}}/en/latest/api-management-overview/tools-for-api-development/#option-2-generate-k8s-custom-resources-using-config-generator-tool-and-deploy-the-api-using-kubernetes-client) | ||
|
||
### Step 2 - Add the request redirection filters to the HTTPRoute CR | ||
|
||
A sample request redirection configuration for an HTTPRoute is given below. | ||
|
||
``` | ||
filters: | ||
- type: "RequestRedirect" | ||
requestRedirect: | ||
scheme: "https" | ||
hostname: "httpbin.org" | ||
path: | ||
type: "ReplaceFullPath" | ||
replaceFullPath: "/anything" | ||
statusCode: 301 | ||
``` | ||
|
||
This policy will redirect an incoming request to the GET /employee route with a 301 status code. | ||
|
||
The complete HTTPRoute with this configuration is given below. | ||
|
||
``` | ||
apiVersion: "gateway.networking.k8s.io/v1beta1" | ||
kind: "HTTPRoute" | ||
metadata: | ||
name: "production-httproute" | ||
spec: | ||
hostnames: | ||
- "default.gw.wso2.com" | ||
rules: | ||
- matches: | ||
- path: | ||
type: "RegularExpression" | ||
value: "/employee" | ||
method: "GET" | ||
filters: | ||
- type: "RequestRedirect" | ||
requestRedirect: | ||
scheme: "https" | ||
hostname: "httpbin.org" | ||
path: | ||
type: "ReplaceFullPath" | ||
replaceFullPath: "/anything" | ||
statusCode: 301 | ||
parentRefs: | ||
- group: "gateway.networking.k8s.io" | ||
kind: "Gateway" | ||
name: "wso2-apk-default" | ||
sectionName: "httpslistener" | ||
``` | ||
|
||
!!! Note | ||
An HTTPRoute rule that has a RequestRedirect filter cannot have a backendRef or a URLRewrite filter attached. | ||
|
||
### Step 3 - Deploy the API in APK | ||
|
||
You can deploy the API using the following command. Replace <namespace> with the correct namespace. | ||
``` | ||
kubectl apply -f . -n <namespace> | ||
``` | ||
|
||
### Step 4 - Generate an access token | ||
|
||
Follow the [Generate Access Token](../../../develop-and-deploy-api/security/generate-access-token.md) documentation to generate an access token. | ||
|
||
### Step 5 - Invoke the API | ||
|
||
You can invoke the API using the following command. | ||
|
||
``` | ||
curl --location 'https://default.gw.wso2.com:9095/employee/1.0/employee' \ | ||
--header 'Host: default.gw.wso2.com' \ | ||
--header 'Authorization: Bearer <accessToken> -I | ||
``` | ||
|
||
Once you have invoked the above, you will see the 301 status code and the `Location` header containing the new URL. | ||
|
||
``` | ||
HTTP/2 301 | ||
location: https://httpbin.org/anything?id=1 | ||
vary: Accept-Encoding | ||
server: envoy | ||
``` |
92 changes: 92 additions & 0 deletions
92
...d-attach-api-policies/redirect-request-filters/redirect-request-via-rest-api.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Request Redirection via REST API | ||
|
||
Request redirection allows you to send clients to a different URL. This can be useful for changing old URLs to new ones or directing traffic based on specific conditions. Request redirection can be configured via the apk-conf file as follows. | ||
|
||
### Step 1 - Get the API configuration | ||
|
||
Here, you can follow the steps in [Create an API](../../../get-started/quick-start-guide.md) documentation and save this content into a file named `EmployeeService.apk-conf`. You can use this apk-conf file for the rest of this guide. | ||
|
||
### Step 2 - Add the request redirection policy to the apk-conf file | ||
|
||
A sample request redirection configuration is given below. | ||
|
||
``` | ||
- target: "/employee" | ||
verb: "GET" | ||
secured: false | ||
scopes: [] | ||
operationPolicies: | ||
request: | ||
- policyName: RequestRedirect | ||
policyVersion: v1 | ||
parameters: | ||
url: https://httpbin.org/anything | ||
statusCode: 301 | ||
``` | ||
|
||
This policy will redirect an incoming request to the GET /employee route with a 301 status code. | ||
|
||
The complete apk-conf file with this configuration is given below. | ||
|
||
``` | ||
id: "redirect-request-api" | ||
name: "EmployeeServiceAPI" | ||
basePath: "/employee" | ||
version: "1.0" | ||
type: "REST" | ||
defaultVersion: false | ||
endpointConfigurations: | ||
production: | ||
endpoint: https://httpbin.org/anything | ||
operations: | ||
- target: "/employee" | ||
verb: "GET" | ||
secured: false | ||
scopes: [] | ||
operationPolicies: | ||
request: | ||
- policyName: RequestRedirect | ||
policyVersion: v1 | ||
parameters: | ||
url: https://httpbin.org/anything | ||
statusCode: 301 | ||
- target: "/employee" | ||
verb: "POST" | ||
secured: true | ||
scopes: [] | ||
- target: "/employee/{employeeId}" | ||
verb: "PUT" | ||
secured: true | ||
scopes: [] | ||
- target: "/employee/{employeeId}" | ||
verb: "DELETE" | ||
secured: true | ||
scopes: [] | ||
``` | ||
### Step 3 - Deploy the API in APK | ||
|
||
Refer to the [Deploy the API in APK](../../../get-started/quick-start-guide.md#deploy-the-api-in-apk) to deploy the API using APK configuration. | ||
|
||
### Step 4 - Generate an access token | ||
|
||
Follow the [Generate Access Token](../../../develop-and-deploy-api/security/generate-access-token.md) documentation to generate an access token. | ||
|
||
### Step 5 - Invoke the API | ||
|
||
You can invoke the API using the following command. | ||
|
||
``` | ||
curl --location 'https://default.gw.wso2.com:9095/employee/1.0/employee' \ | ||
--header 'Host: default.gw.wso2.com' \ | ||
--header 'Authorization: Bearer <accessToken> -I | ||
``` | ||
|
||
Once you have invoked the above, you will see the 301 status code and the `Location` header containing the new URL. | ||
|
||
``` | ||
HTTP/2 301 | ||
location: https://httpbin.org/anything?id=1 | ||
vary: Accept-Encoding | ||
date: Mon, 08 Jul 2024 08:05:57 GMT | ||
server: envoy | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters