Build your own API gateway in Go.
Lura is the open source framework for assembling high-performance, stateless API gateways from small, reusable components. The engine behind KrakenD.
go get github.com/luraproject/lura/v3
Simple, stateless and fast by design.
Lura is the engine of KrakenD and shares its philosophy: the gateway should be a thin, fast layer that does the API work once, so neither clients nor backends have to. Its design follows a short set of rules:
- Reactive is key
- Failing fast is better than succeeding slow
- The simpler, the better
- Everything is pluggable
- Each request is processed in its own request-scoped context
Stateless
No database and no coordination between nodes. Every instance works on its own, so you scale by adding instances.
Declarative
The configuration describes the whole service: endpoints, backends and the middlewares on each of them. Behavior is data you keep in version control, not code to deploy.
Built once, served from memory
At start-up Lura reads the configuration and builds a pipe for every endpoint. Requests find their handler directly, so adding endpoints doesn't slow the gateway down.
Everything is pluggable
Routers, proxies and middlewares are Go interfaces. Choose the router, stack only the middlewares you need, or write your own.
Fail fast
Failing fast is better than succeeding slow. Every request runs in its own context with timeouts, and work that can no longer help the client is cancelled.
Not tied to HTTP
Lura is a set of Go libraries for Layer 7 gateways. The same building blocks serve other transports, such as an RPC gateway.
Aggregation: one request in, many backends out.
Backend services are rarely shaped the way a user interface needs them. A mobile front page might need four calls. With a gateway built on Lura, the client makes one call to lura.server/frontpage/{id_user}: Lura calls the backends concurrently, merges the responses and returns only the fields the screen uses.
Clients stay isolated from backend contracts, and backends no longer each handle shared concerns such as authentication or rate limiting: the gateway does it once.
api.store.server/products
api.store.server/marketing-promos
api.users.server/users/{id_user}
api.users.server/shopping-cart/{id_user}A gateway in one Go file.
Lura is a Go library you include in your own application. This program reads a configuration file and serves every endpoint it declares, using the gin router:
package main
import (
"flag"
"log"
"os"
"github.com/luraproject/lura/v3/config"
"github.com/luraproject/lura/v3/logging"
"github.com/luraproject/lura/v3/proxy"
"github.com/luraproject/lura/v3/router/gin"
)
func main() {
port := flag.Int("p", 0, "Port of the service")
logLevel := flag.String("l", "ERROR", "Logging level")
debug := flag.Bool("d", false, "Enable the debug")
configFile := flag.String("c", "/etc/lura/configuration.json", "Path to the configuration filename")
flag.Parse()
parser := config.NewParser()
serviceConfig, err := parser.Parse(*configFile)
if err != nil {
log.Fatal("ERROR:", err.Error())
}
serviceConfig.Debug = serviceConfig.Debug || *debug
if *port != 0 {
serviceConfig.Port = *port
}
logger, _ := logging.NewLogger(*logLevel, os.Stdout, "[LURA]")
routerFactory := gin.DefaultFactory(proxy.DefaultFactory(logger), logger)
routerFactory.New().Run(serviceConfig)
}Extend your gateway with components and middlewares.
Lura is built to be extended: features come as components and middlewares, small Go modules you stack in your own gateway. The ones below build against Lura v3. Today the KrakenD team, Lura's main contributor, maintains all of them, and each repository explains how to wire it in.
Security
- krakend-jose
JSON Web Token (JWT) validation and signing, with key (JWK) fetching and caching.
- krakend-cors
Cross-origin resource sharing (CORS) support.
- krakend-httpsecure
HTTP security headers and policies.
- krakend-botdetector
Detects and rejects bots by their User-Agent.
- krakend-basicauth
HTTP Basic authentication against bcrypt hashes.
- bloomfilter
Rotating, distributed Bloom filter, used to revoke tokens.
- krakend-oauth2-clientcredentials
OAuth2 client credentials grant for calls to backends.
Traffic
- krakend-ratelimit
Rate limiting for endpoints and backends.
- krakend-circuitbreaker
Circuit breaker for backends.
- krakend-httpcache
Caches backend responses following their HTTP cache headers.
Logic and transformation
- krakend-cel
Accepts or rejects requests and responses with CEL expressions.
- krakend-lua
Lua scripts that modify requests and responses.
- krakend-martian
Request and response modifiers based on Google martian.
- krakend-jsonschema
Validates request bodies against a JSON Schema.
- krakend-xml
XML encoding support.
- krakend-rss
RSS feed encoding support.
Backends and messaging
- krakend-amqp
AMQP (RabbitMQ) consumer, producer and async agent.
- krakend-pubsub
Publish/subscribe backends: Kafka, NATS, RabbitMQ and cloud queues.
- krakend-lambda
Calls AWS Lambda functions as backends.
Observability
- krakend-otel
OpenTelemetry metrics and traces.
- krakend-metrics
Metrics collection for the router, proxy and backend layers.
- krakend-gologging
Logger.
- krakend-logstash
JSON log format for Logstash.
- krakend-gelf
GELF (Graylog) log writer.
Configuration and tooling
- krakend-flexibleconfig
Builds the configuration from templates, settings files and partials.
- krakend-koanf
Configuration parser based on koanf.
- krakend-cobra
Command-line interface based on cobra.
- krakend-audit
Audits a configuration and returns security recommendations.
- krakend-config2dot
Turns a configuration into a Graphviz graph.
- krakend-postman
Generates a Postman collection from a configuration.
Built a component or middleware for Lura?
Add it to this list. The site is a single HTML file, so it takes one line: edit the page on GitHub and open a pull request with your module, its repository and a short description.
Prefer a ready-made gateway?
KrakenD Community Edition is built on Lura and ships with many of these components, assembled into a single binary you configure with a JSON file instead of Go code. It is available as a Docker Official Image:
docker run -it -p "8080:8080" krakendAlso as binaries and packages for several platforms: see downloads and the KrakenD Community Edition page.
A Linux Foundation project.
Lura has been hosted by the Linux Foundation since 2021, when the KrakenD team donated the framework (announcement). It is governed by its Technical Charter and follows the LF Projects Code of Conduct.
Technical Charter (PDF)
Adopted on April 14, 2021. It covers:
- Mission and scope of the project
- Technical Steering Committee
- TSC voting
- Compliance with policies
- Community assets
- General rules and operations
- Intellectual property policy
- Amendments
Built in the open.
Issues
The preferred place for bugs, feature requests and questions.
Contributing
Pull requests are welcome. Discuss larger changes in an issue first.
Security
Report vulnerabilities privately, as the security policy explains.
Slack
Join #lura on the Gophers Slack.
Please don't contact individual project members for support.
The people behind Lura.
Founders
Lura began in 2016 as the KrakenD framework, created by Daniel López, Daniel Ortiz and Albert Lombarte, the founders of KrakenD.
The name
Proposed by Carmela Rubiños. Lura is Galician for squid, a fitting name for the engine of KrakenD, which is named after the Kraken, the giant sea creature of Norse legend. Lura is the Kraken's offspring, and its logo draws those many arms, each reaching a different backend.
The Linux Foundation
Scott Nicholas, of the Linux Foundation, facilitated the project's move to the Linux Foundation in 2021.
Launch partners
99P Labs (backed by Honda), Ardan Studios, Hepsiburada, Openroom, Postman, Skalena and Stayforlong supported the project's launch at the Linux Foundation in 2021 (announcement).
Contributors
Major contributions from David Hontecillas and Jorge Tarrero, and from everyone who has sent code, reviews and issues. Thank you.