Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/transferwise/cable
Simple and minimalistic url rewriter
https://github.com/transferwise/cable
url-rewrite
Last synced: 2 months ago
JSON representation
Simple and minimalistic url rewriter
- Host: GitHub
- URL: https://github.com/transferwise/cable
- Owner: transferwise
- License: apache-2.0
- Created: 2017-05-26T10:01:58.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-04T23:36:15.000Z (9 months ago)
- Last Synced: 2024-04-14T05:18:17.827Z (9 months ago)
- Topics: url-rewrite
- Language: Java
- Homepage:
- Size: 65.4 KB
- Stars: 1
- Watchers: 109
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Cable [![CircleCI](https://circleci.com/gh/transferwise/cable/tree/master.svg?style=shield)](https://circleci.com/gh/transferwise/cable/tree/master) [![GitHub release](https://jitpack.io/v/transferwise/cable.svg)](https://github.com/transferwise/cable/releases/latest)
A simple and minimalistic url rewrite module.
## Installation
Just add the following configuration to your `build.gradle` file
```gradle
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}dependencies {
compile 'com.github.transferwise.cable:cable-starter:2.0.0'
}
```If you want to use the servlet filters by your own avoiding auto-configuration, just include the `cable-core` dependency
```gradle
compile 'com.github.transferwise.cable:cable-core:2.0.0'
```## Configuration
Using the starter module you can easily add new rewrite rules to your `application.yml`
```yaml
cable:
rewrites:
- {from: "/path", to: "/more/interesting/path"}
- {from: "^/([a-z]{2})/(.*)$", to: "/$1/blog/$2"}
}
```## Usage
In Thymeleaf templates it will work automatically with link url expressions `@{...}`
```html
This is a test
```It will also automatically work on redirects within your controllers.
## Advanced usage
You can use lambda functions tu create more complex filters, so you will rewrite the url under controlled circumstances.
Let's imagine you want to rewrite only the urls of requests served under "/path":
```java
@Bean
public Filter urlRewriteFilter() {
return new UrlRewriteFilter()
.rewrite("/test", "/test2", r -> r.getRequestURI().contains("/path"));
}
```