{"id":46549930,"url":"https://github.com/onliner/krakend-fallback","last_synced_at":"2026-03-07T03:09:35.770Z","repository":{"id":341665669,"uuid":"1170586798","full_name":"onliner/krakend-fallback","owner":"onliner","description":"Server plugin that allows configuring route-based rules to enforce required response fields (returning an error if missing) and inject default values for absent fields.","archived":false,"fork":false,"pushed_at":"2026-03-02T20:11:29.000Z","size":12,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-03-02T23:07:31.989Z","etag":null,"topics":["api-gateway","fallback","krakend","krakend-plugin"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onliner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-02T09:40:36.000Z","updated_at":"2026-03-02T09:44:56.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/onliner/krakend-fallback","commit_stats":null,"previous_names":["onliner/krakend-fallback"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/onliner/krakend-fallback","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onliner%2Fkrakend-fallback","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onliner%2Fkrakend-fallback/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onliner%2Fkrakend-fallback/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onliner%2Fkrakend-fallback/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onliner","download_url":"https://codeload.github.com/onliner/krakend-fallback/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onliner%2Fkrakend-fallback/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30206351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T19:07:06.838Z","status":"online","status_checked_at":"2026-03-07T02:00:06.765Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-gateway","fallback","krakend","krakend-plugin"],"created_at":"2026-03-07T03:09:34.923Z","updated_at":"2026-03-07T03:09:35.758Z","avatar_url":"https://github.com/onliner.png","language":null,"readme":"# Krakend Fallback\n\nServer plugin for **KrakenD** that allows configuring route-based rules to:\n\n- Enforce required response fields (returning an error if missing)\n- Inject default values for absent fields\n- Extract and propagate backend errors (`error_*`) when required fields are missing\n\n---\n\n## Overview\n\nThe plugin works as a **server middleware**.\n\nFor configured routes it:\n\n1. Intercepts the aggregated JSON response\n2. If response is not `2xx` or not JSON → passes it through untouched\n3. If JSON and successful:\n   - Injects default fields (if missing)\n   - Validates required fields\n   - If required field is missing:\n     - Looks for `error_*` keys in the response\n     - Sorts them\n     - Returns the first backend error\n     - If no backend error found → returns `500`\n\n---\n\n## Example KrakenD Configuration\n\n```json\n{\n  \"plugin/http-server\": {\n    \"name\": [\"onliner/krakend-fallback\"],\n    \"onliner/krakend-fallback\": {\n      \"routes\": [\n        {\n          \"path\": \"/products/{product}/positions\",\n          \"required\": [\"product\"],\n          \"default\": {\n            \"positions\": []\n          }\n        }\n      ]\n    }\n  }\n}\n```\n\n---\n\n## Route Configuration\n\n### `path`\n\nPath template using `{param}` syntax.\n\nExample:\n\n```\n/products/{product}/positions\n```\n\n---\n\n### `required`\n\nList of top-level JSON keys that must exist in the final aggregated response.\n\nIf any key is missing:\n\n- Plugin searches for `error_*` fields\n- If found → returns the first backend error\n- If not found → returns `500 Internal Server Error`\n\n---\n\n### `default`\n\nMap of fields to inject if they are missing.\n\nDefaults are only applied for successful `2xx` JSON responses.\n\nExample:\n\n```json\n\"default\": {\n  \"positions\": [],\n  \"shops\": null\n}\n```\n\n---\n\n## Backend Error Format\n\nBackend errors must follow this structure inside the aggregated response:\n\n```json\n{\n  \"error_1\": {\n    \"http_status_code\": 500,\n    \"http_body\": \"{\\\"message\\\":\\\"backend failed\\\"}\",\n    \"http_body_encoding\": \"application/json\"\n  }\n}\n```\n\n### Fields\n\n- `http_status_code` – HTTP status to return\n- `http_body` – raw response body\n- `http_body_encoding` – Content-Type header (optional, defaults to `text/plain`)\n\nIf multiple `error_*` keys exist, the plugin:\n\n1. Sorts them lexicographically\n2. Returns the first one\n\n## Notes\n\n- Plugin modifies only successful `2xx` JSON responses\n- Original headers are preserved when modifying response\n- `Content-Length` is recalculated when body is modified\n- Thread-safe and race-tested\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonliner%2Fkrakend-fallback","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonliner%2Fkrakend-fallback","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonliner%2Fkrakend-fallback/lists"}