github.com/hellofresh/janus@v0.0.0-20230925145208-ce8de8183c67/docs/proxy/strip_uri_property.md (about) 1 ##### The `strip_path` property 2 3 It may be desirable to specify a URI prefix to match an API, but not 4 include it in the upstream request. To do so, use the `strip_path` boolean 5 property by configuring an API like this: 6 7 ```json 8 { 9 "name": "My API", 10 "proxy": { 11 "strip_path" : true, 12 "listen_path": "/service/*", 13 "upstreams" : { 14 "balancing": "roundrobin", 15 "targets": [ 16 {"target": "http://my-api.com"} 17 ] 18 }, 19 "methods": ["GET"] 20 } 21 } 22 ``` 23 24 Enabling this flag instructs Janus that when proxying this API, it should **not** 25 include the matching URI prefix in the upstream request's URI. For example, the 26 following client's request to the API configured as above: 27 28 ```http 29 GET /service/path/to/resource HTTP/1.1 30 Host: my-api.com 31 ``` 32 33 Will cause Janus to send the following request to your upstream service: 34 35 ```http 36 GET /path/to/resource HTTP/1.1 37 Host: my-api.com 38 ``` 39 40 The `strip_path` property can be used in tandem with `Named URL Parameters`. 41 i.e: 42 ```json 43 { 44 "name": "My API", 45 "proxy": { 46 "strip_path" : true, 47 "listen_path": "/prepath/{service}/*", 48 "upstreams" : { 49 "balancing": "roundrobin", 50 "targets": [ 51 {"target": "http://{service}.com"} 52 ] 53 }, 54 "methods": ["GET"] 55 } 56 } 57 ``` 58 59 Akin to the previous example a request to janus like this: 60 ```http 61 GET /prepath/my-service/path/to/resource HTTP/1.1 62 Host: janus 63 ``` 64 65 Will cause Janus to send the following request to your upstream service: 66 67 ```http 68 GET /path/to/resource HTTP/1.1 69 Host: my-service.com 70 ``` 71 72 This is because when the `strip_path` property is set to **true** and a `Named URL parameter` is used, the first instance of each section of the `listen_path` (delineated by `/`) will be removed from the upstream request. This includes the parameter name and regex. 73 <br> 74 In addition to that, the first instance of each `Named URL parameter` will be removed from the upstream request.