Focus on your application.
Let Lily manage dependencies and the application lifecycle. Concepts, examples, and guides for building HTTP applications in Rust.
Dependencies, brought together.
Define your services. Let the container handle creation, sharing and cleanup.
Dependency injection 02From startup to shutdown.
A shared application lifecycle for the server, requests and managed resources.
Application lifecycleLily is a Rust framework that lets you build applications with controllers, services, and policies you explicitly choose. The lilyrs facade on crates.io exposes the HTTP component as lilyrs::http_api through the http-api feature. The underlying lily_http_api manages both the HTTP server and the lifecycle of the application in which these components work together.
More than a route. Creating services, opening a scope for each request, and cleaning up resources during shutdown are all parts of the same application model.
Two foundations of the application#
Dependency injection. Declare dependencies with Injectable and receive them in your services with #[inject]. The container creates objects according to the lifetime you choose and closes their resources. Controller actions resolve services from the active request's scope through Service<T>.
Lifecycle ownership. AppBuilder collects your choices. build prepares configuration and components. start runs the server. During shutdown, Lily terminates managed work, request resources, and its own DI container in the correct order.
A small starting point#
Once you have defined a controller, the application starts with the following chain. This snippet belongs inside an async function; the complete file and dependencies are on the first HTTP application page.
AppBuilder::new("127.0.0.1:8080")
.tls_disabled()
.build().await?
.start().await?;build does not open a socket yet. start opens the listener. The normal start also manages platform signals; Ctrl+C initiates graceful shutdown.
Where to go next#
Run your first application. Then learn about the application lifecycle and dependency injection. HTTP contracts, security policies, data access, and running the application build on this foundation.
| What you need | Where to start |
|---|---|
| Create an HTTP endpoint | Controllers and routes |
| Accept JSON and return a response | Request bodies · Responses |
| Identity and access control | Authentication · Guards |
| Browser security policies | Cookies · CORS · CSRF |
| Connect to a database | PostgreSQL · MongoDB |
| Send files or live data | Streaming · SSE |
| Publish an API contract | OpenAPI |
Shared infrastructure, three application types#
lily_http_api, lily_websocket, and lily_consumer use the same DI infrastructure. lily_injection provides the container, lily_injectable_derive generates registrations, and lily_injection_registry connects those registrations to the runtime. You do not need to create registry entries manually.
This guide covers HTTP API in detail. For connection and message applications, see the WebSocket guide. For applications that consume messages, follow the Consumer guide.
Types of support in this guide#
Built-in support is behavior supplied by the framework, such as routing, middleware, cookies, CORS, and OpenAPI. An integration comes through an additional Lily crate, such as PostgreSQL or MongoDB. An application recipe connects your own policy to existing extension points, such as token verification, choosing a session store, or HTTP rate limiting.
The guide is based on the 0.1.0 API surface verified in source code. The reference lists the source revision, the scope of example validation, and differences from older documents.
Sources for this page v0.1.0
This guide is based on the reviewed framework commit.