> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apinizer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Reading Request URL Path and Changing Backend Address

> Reading request URL path with Groovy script and dynamically changing backend address

## Scenario

Let's assume that [Petstore API](https://petstore.swagger.io/v2/swagger.json) has been introduced to Apinizer when Apinizer worker is running on `http://<SERVICE_IP>:30080/apigateway/` address.

* API Proxy's relative path value: `"/apigateway/petstore"`
* API Proxy's full address: `http://<SERVICE_IP>:30080/apigateway/petstore/`
* Backend Routing URL: `https://petstore.swagger.io/v2`

## Usage

When accessing the following endpoint with GET request:

```
http://<SERVICE_IP>:30080/apigateway/petstore/pet/findByStatus?status=pending
```

The `requestUrlFromClient` variable in the script policy contains the value `"/pet/findByStatus"`. If it were a SOAP service, the value of this variable would be the SOAP method name.

When the value `"/xxx/yyy"` is given to the `requestBackendUrlToTargetAPI` variable in the script policy, regardless of which method the request came to, the request goes to the following address with the current query param added:

```
https://petstore.swagger.io/v2/xxx/yyy?status=pending
```

<Note>
  This script should be run on the request line (Request Policy) because it uses the `requestUrlFromClient` and `requestBackendUrlToTargetAPI` variables.
</Note>
