Create endpoint to list redirect rules for a specific short URL

This commit is contained in:
Alejandro Celaya
2024-02-27 21:00:53 +01:00
parent 721e3d9ef9
commit 33729289c7
17 changed files with 382 additions and 34 deletions

View File

@@ -0,0 +1,39 @@
{
"type": "object",
"required": ["priority", "longUrl", "conditions"],
"properties": {
"longUrl": {
"description": "Long URL to redirect to when this condition matches",
"type": "string"
},
"priority": {
"description": "Order in which attempting to match the rule. Lower goes first",
"type": "number"
},
"conditions": {
"description": "List of conditions that need to match in order to consider this rule matches",
"type": "array",
"items": {
"type": "object",
"required": ["name", "type", "matchKey", "matchValue"],
"properties": {
"name": {
"type": "string",
"description": "Unique condition name"
},
"type": {
"type": "string",
"enum": ["device", "language", "query"],
"description": "The type of the condition, which will condition the logic used to match it"
},
"matchKey": {
"type": ["string", "null"]
},
"matchValue": {
"type": "string"
}
}
}
}
}
}

View File

@@ -0,0 +1,144 @@
{
"get": {
"operationId": "listShortUrlRedirectRules",
"tags": [
"Redirect rules"
],
"summary": "List short URL redirect rules",
"description": "Returns the list of redirect rules for a short URL.",
"parameters": [
{
"$ref": "../parameters/version.json"
},
{
"$ref": "../parameters/shortCode.json"
},
{
"$ref": "../parameters/domain.json"
}
],
"security": [
{
"ApiKey": []
}
],
"responses": {
"200": {
"description": "The list of rules",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"redirectRules": {
"type": "array",
"items": {
"$ref": "../definitions/ShortUrlRedirectRule.json"
}
}
}
},
"example": {
"redirectRules": [
{
"longUrl": "https://example.com/android-en-us",
"priority": 1,
"conditions": [
{
"name": "device-android",
"type": "device",
"matchValue": "android",
"matchKey": null
},
{
"name": "language-en-US",
"type": "language",
"matchValue": "en-US",
"matchKey": null
}
]
},
{
"longUrl": "https://example.com/fr",
"priority": 2,
"conditions": [
{
"name": "language-fr",
"type": "language",
"matchValue": "fr",
"matchKey": null
}
]
},
{
"longUrl": "https://example.com/query-foo-bar-hello-world",
"priority": 3,
"conditions": [
{
"name": "query-foo-bar",
"type": "query",
"matchKey": "foo",
"matchValue": "bar"
},
{
"name": "query-hello-world",
"type": "query",
"matchKey": "hello",
"matchValue": "world"
}
]
}
]
}
}
}
},
"404": {
"description": "No URL was found for provided short code.",
"content": {
"application/problem+json": {
"schema": {
"allOf": [
{
"$ref": "../definitions/Error.json"
},
{
"type": "object",
"required": ["shortCode"],
"properties": {
"shortCode": {
"type": "string",
"description": "The short code with which we tried to find the short URL"
},
"domain": {
"type": "string",
"description": "The domain with which we tried to find the short URL"
}
}
}
]
},
"examples": {
"API v3 and newer": {
"$ref": "../examples/short-url-not-found-v3.json"
},
"Previous to API v3": {
"$ref": "../examples/short-url-not-found-v2.json"
}
}
}
}
},
"default": {
"description": "Unexpected error.",
"content": {
"application/problem+json": {
"schema": {
"$ref": "../definitions/Error.json"
}
}
}
}
}
}
}

View File

@@ -42,6 +42,10 @@
"name": "Short URLs",
"description": "Operations that can be performed on short URLs"
},
{
"name": "Redirect rules",
"description": "Handle dynamic rule-based redirects"
},
{
"name": "Tags",
"description": "Let you handle the list of available tags"
@@ -79,6 +83,10 @@
"$ref": "paths/v1_short-urls_{shortCode}.json"
},
"/rest/v{version}/short-urls/{shortCode}/redirect-rules": {
"$ref": "paths/v3_short-urls_{shortCode}_redirect-rules.json"
},
"/rest/v{version}/tags": {
"$ref": "paths/v1_tags.json"
},