# Create forwarding rules for application load balancer - CreateRule

## Overview

Create a forwarding rule for the application load balancer listener






## Definition

### Public Parameters

| Parameter Name | Type | Description Information | Required |
|:---|:---|:---|:---|
| **Action**     | string  | Corresponding API command name, the current API is `CreateRule`.                      | **Yes** |
| **PublicKey**  | string  | The user's public key can be obtained from [Console](https://console.scloudsg.com/uaccount/api_manage)                                             | **Yes** |
| **Signature**  | string  | User signature generated based on public key and API command, see [Signature Algorithm](/docs/api/summary/signature.md)  | **Yes** |

### Request Parameters

| Parameter Name | Type | Description Information | Required |
|:---|:---|:---|:---|
| **Region** | string | Region. See [List of Regions and Availability Zones](/docs/api/summary/regionlist) |**Yes**|
| **ProjectId** | string | Project ID. If not filled in, the default project is used, sub-accounts must be filled in. Please refer to the [GetProjectList interface](/docs/api/summary/get_project_list). |**Yes**|
| **LoadBalancerId** | string | ID of the Load Balancing Instance |**Yes**|
| **ListenerId** | string | Listener's ID |**Yes**|
| **RuleConditions.N.Type** | string | Matching condition type. Limited enumeration values: "Host"/"Path". |**Yes**|
| **RuleConditions.N.HostConfig.MatchMode** | string | Matching method. Limited enumeration values: 'Regular'/'Wildcard', default value: 'Regular'. |No|
| **RuleConditions.N.HostConfig.Values.N** | string | Value. Currently, only arrays of length 1 are supported; the value must meet the conditions of the relevant matching method; it is mandatory to fill in when matching domain names. |No|
| **RuleConditions.N.PathConfig.Values.N** | string | Value. Currently only supports an array length of 1; the value must meet relevant conditions; must be filled in when path matching. |No|
| **RuleActions.N.Type** | string | Action Type. Limited enumeration values: "Forward", "InsertHeader", "Cors", "FixedResponse", "RemoveHeader". Only the structure corresponding to Type will be processed. |**Yes**|
| **RuleActions.N.ForwardConfig.Targets.N.Id** | string | The identifier ID of the backend service node being forwarded. It is limited to the service node pool of the listener; the array length can be 0; when the array length of the configured forwarding service node is not 0, the ID is required. |No|
| **RuleActions.N.ForwardConfig.Targets.N.Weight** | int | The weight of the backend service node being forwarded. Only valid when the load balancing algorithm of the listener is weighted round robin. |No|
| **RuleActions.N.Order** | int | The execution order of forwarding rule actions ranges from 1 to 1000, with actions executed from smallest to largest value. The value cannot be empty or duplicated.<br /><br />Forward and FixedResponse types of actions do not consider Order and are executed last. |No|
| **RuleActions.N.InsertHeaderConfig.Key** | string | The inserted header field name must be 1 to 40 characters long and can include uppercase and lowercase letters a-z, numbers, underscores (_), and hyphens (-). The header field name cannot be used repeatedly in InsertHeader.<br /><br />The header field cannot use the following (case insensitive):<br /><br />x-real-ip, x-forwarded-for, x-forwarded-proto, x-forwarded-srcport, ucloud-alb-trace, connection, upgrade, content-length, transfer-encoding, keep-alive, te, host, cookie, remoteip, authority. |No|
| **RuleActions.N.InsertHeaderConfig.ValueType** | string | Header field content type. Values:<br />UserDefined: User specified.<br /><br />ReferenceHeader: Referencing a field from the user's request header.<br /><br />SystemDefined: System defined. |No|
| **RuleActions.N.InsertHeaderConfig.Value** | string | Content of the inserted header field.<br /><br />When ValueType is SystemDefined, the values are as follows:<br />ClientSrcPort: Client port.<br />ClientSrcIp: Client IP address.<br />Protocol: Protocol of the client's request (HTTP or HTTPS).<br />RuleID: ID of the forwarding rule hit by the client's request.<br />ALBID: ALB ID.<br />ALBPort: ALB port.<br /><br />When ValueType is UserDefined:<br /><br />You can customize the header field content, with a length limit of 1\~128 characters, supporting printable characters in the ASCII range where ch >= 32 && ch < 127, excluding $.<br /><br />When ValueType is ReferenceHeader:<br /><br />You can reference a specific field from the request header fields, with a length limit of 1\~128 characters, supporting lowercase letters a\~z, numbers, hyphens (-), and underscores (_). |No|
| **RuleActions.N.RemoveHeaderConfig.Key** | string | The header field names to be deleted, currently only the following default configured fields can be deleted<br /><br />X-Real-IP, X-Forwarded-For, X-Forwarded-Proto, X-Forwarded-SrcPort |No|
| **RuleActions.N.CorsConfig.AllowOrigin.N** | string | Allowed access source list. Supports configuring a single element *, or one or more values.<br /><br />A single value must start with http:// or https://, followed by a correct domain name or a primary wildcard domain. (Example: http://*.test.abc.example.com)<br />A single value can omit the port or specify a port, with a port range of 1\~65535.<br />Supports up to 5 values. |No|
| **RuleActions.N.CorsConfig.AllowHeaders.N** | string | List of Headers allowed for cross-origin. Supports configuration as * or one or more value entries. A single value entry may only contain uppercase and lowercase letters, numbers, and cannot start or end with an underscore (_) or hyphen (-), with a maximum length limit of 32 characters. Supports up to 20 entries. |No|
| **RuleActions.N.CorsConfig.ExposeHeaders.N** | string | List of allowed exposed Headers. Supports configuration as * or one or more value(s). A single value is only allowed to contain uppercase and lowercase letters, numbers, and cannot start or end with an underscore (_) or hyphen (-), with a maximum length of 32 characters. Supports up to 20 values. |No|
| **RuleActions.N.CorsConfig.AllowMethods.N** | string | Select the allowed HTTP methods for cross-domain access. Values:<br /><br />GET.<br />POST.<br />PUT.<br />DELETE.<br />HEAD.<br />OPTIONS.<br />PATCH. |No|
| **RuleActions.N.CorsConfig.AllowCredentials** | string | Allow carrying credential information. Values:<br /><br />on: Yes.<br />off: No. |No|
| **RuleActions.N.CorsConfig.MaxAge** | int | Maximum cache time for preflight requests in the browser, in seconds.<br /><br />Value range: -1\~172800. |No|
| **RuleActions.N.FixedResponseConfig.HttpCode** | int | Returned HTTP response codes, only supports 2xx, 4xx, 5xx numbers, where x is any digit. |No|
| **RuleActions.N.FixedResponseConfig.Content** | string | Returned fixed content. Supports storage up to 1 KB, only supports printable characters within the ASCII code range ch >= 32 && ch < 127, excluding $. |No|
| **Pass** | boolean | Whether the rule is ignored when the service node to be forwarded is empty. The default value is true. |No|

### Response Field

| Field Name | Type | Description Information | Required |
|:---|:---|:---|:---|
| **RetCode** | int | Return status code. If it is 0, it means successful return. If it is not 0, it means failure. |**Yes**|
| **Action** | string | Operation command name. |**Yes**|
| **Message** | string | Returns an error message, providing detailed description when `RetCode` is non-zero. |No|
| **RuleId** | string | ID of the forwarding rule |**Yes**|




## Example

### Request Example
    
```
https://api.scloudsg.com/?Action=CreateRule
&Region=cn-zj
&ProjectId=KkLjsPqn
&LoadBalancerId=TpQFMTyp
&ListenerId=TBLRaFqM
&RuleConditions.n.Type=OwQlzYTk
&RuleActions.n.Type=CdXoaIEM
&RuleConditions.n.HostConfig.MatchMode=PVAsSDML
&RuleConditions.n.HostConfig.Values.n=leqEAWWl
&RuleConditions.n.PathConfig.Values.n=PwuAChmC
&RuleActions.n.ForwardConfig.Targets.n.Id=kJkvikIW
&RuleActions.n.ForwardConfig.Targets.n.Weight=2
&Pass=true
&RuleActions.n.Order=8
&RuleActions.n.InsertHeaderConfig.Key=FggaGvNf
&RuleActions.n.InsertHeaderConfig.ValueType=fGRElWKu
&RuleActions.n.InsertHeaderConfig.Value=tONXuVLL
&RuleActions.n.RemoveHeaderConfig.Key=yPJEuNJS
&RuleActions.n.CorsConfig.AllowOrigin.n=LIsTRKRs
&RuleActions.n.CorsConfig.AllowHeaders.n=hxwaXQFI
&RuleActions.n.CorsConfig.ExposeHeaders.n=umwnQzxR
&RuleActions.n.CorsConfig.AllowMethods.n=RNCUBGzF
&RuleActions.n.CorsConfig.AllowCredentials=CPBenoTf
&RuleActions.n.CorsConfig.MaxAge=3
&RuleActions.n.FixedResponseConfig.HttpCode=8
&RuleActions.n.FixedResponseConfig.Content=WzivkLDY
&RuleActions.n.Order=9
&RuleActions.n.InsertHeaderConfig.Key=ejZeJwqb
&RuleActions.n.InsertHeaderConfig.ValueType=lCNCsmJE
&RuleActions.n.InsertHeaderConfig.Value=MkjLDVpA
&RuleActions.n.RemoveHeaderConfig.Key=zOtodzbH
&RuleActions.n.CorsConfig.AllowOrigin.n=GgnvyDiy
&RuleActions.n.CorsConfig.AllowHeaders.n=XEcqLwCf
&RuleActions.n.CorsConfig.ExposeHeaders.n=HJQMCfUp
&RuleActions.n.CorsConfig.AllowMethods.n=MkuDHUmA
&RuleActions.n.CorsConfig.AllowCredentials=bxzcboba
&RuleActions.n.CorsConfig.MaxAge=6
&RuleActions.n.FixedResponseConfig.HttpCode=8
&RuleActions.n.FixedResponseConfig.Content=DChjvFbl
```

### Response Example
    
```json
{
  "Action": "CreateRuleResponse",
  "RetCode": 0,
  "RuleId": "qZjWGzsa"
}
```





