Skip to main content

Gateway Routing

Learn how to configure and manage API routes in the LibreApps Gateway.

Overview

Routing in the LibreApps Gateway is handled by Apache APISIX. It maps incoming URL paths and hostnames to specific backend services.

Configuration

Routes are defined in etcd and can be managed via the Admin API or the APISIX Dashboard.

{
"uri": "/llm/*",
"name": "litellm",
"methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
"plugins": {
"proxy-rewrite": {
"regex_uri": ["^/llm/(.*)", "/$1"]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"litellm:4000": 1
}
}
}

Key Parameters

  • uri: The URL pattern to match (e.g., /llm/*).
  • plugins: A collection of plugins to apply to the route (e.g., proxy-rewrite, key-auth).
  • upstream: The target service where the request should be forwarded.

Dynamic Routing

APISIX supports hot-reloading of configuration. When you add or update a route via the Admin API, the changes take effect immediately without needing to restart the gateway.

Custom Plugins

You can create custom plugins in Lua to extend APISIX's functionality.

local _M = {}

function _M.rewrite(conf, ctx)
-- custom logic here
end

return _M

Best Practices

  • Do this: Use descriptive names for your routes to make the configuration easy to understand.
  • Do this: Enable stripPrefix for most routes to keep the backend service APIs clean.
  • Don't do this: Create overly broad routes (e.g., /**) that might accidentally expose sensitive internal endpoints.