| Crates.io | preroll |
| lib.rs | preroll |
| version | 0.10.1 |
| created_at | 2020-12-08 00:41:55.63063+00 |
| updated_at | 2022-04-07 23:51:41.716272+00 |
| description | Easy boilerplate utilities for Rust http services which use async-std, Tide, Surf, and friends. |
| homepage | |
| repository | https://github.com/eaze/preroll |
| max_upload_size | |
| id | 320665 |
| size | 108,437 |
Easy boilerplate utilities for Rust http services which use async-std, Tide, Surf, and friends.
Allows for service setup with feature-configured built-ins for maximum service consistency with low developer overhead, and for easily integration testing the service without using a live network.
Scroll to the bottom for API Reference
use std::sync::Arc;
use tide::{Request, Route};
struct AppState {
greeting: &'static str,
}
type AppRequest = Request<Arc<AppState>>;
async fn setup_app_state() -> preroll::SetupResult<AppState> {
Ok(AppState {
greeting: "Hello World!",
})
}
fn setup_routes(mut server: Route<'_, Arc<AppState>>) {
server
.at("hello-world")
.get(|req: AppRequest| async move {
Ok(req.state().greeting)
});
}
// The "magic" happens here!
preroll::main!("hello-world", setup_app_state, setup_routes);
main setup via preroll::main!, with optional features automatically configured.preroll::prelude::*; with all extension traits.JsonError.Add-on features must be enabled via cargo features, e.g.
[dependencies.preroll]
version = "0.5"
features = ["honeycomb", "postgres"]
"honeycomb": Enables tracing to honeycomb.io.
HONEYCOMBIO_WRITE_KEY (required).TRACELEVEL, sets the tracing level filter, defaults to info.{service_name}-{environment}.
service_name is from preroll::main!("service_name", ...).environment is from ENVIRONMENT, or defaults to "development"."lambda-http": Changes the HTTP listener to connect to an AWS Lambda execution environment.
PORT, are disregarded."honeycomb" feature is enabled, trace events are written to stdout, and must be collected via
a layer provided by Honeycomb. See: https://docs.honeycomb.io/getting-data-in/integrations/aws/aws-lambda/"postgres": Enables a postgres connection pool with transactions.
PGURL, which should be a properly formatted postgres:// database url.
"postgres://localhost/{service_name}" (default postgres port).service_name is from preroll::main!("service_name", ...).PGMAXCONNECTIONS, default 5 connections.PGMAXLIFETIME, default 30 (minutes).PostgresRequestExt][prelude::PostgresRequestExt] and [test_utils::create_client_and_postgres][]."panic-on-error": Makes the response logger [panic][] on error rather than log.
--release compilation.The following environment variables are read during preroll::main!:
ENVIRONMENT: If this starts with prod, load the production-mode JSON logger, avoid .env.FORCE_DOTENV: Override production-mode, force-load environment from .env.HOST: Sets the hostname that this service will listen on. Defaults to "127.0.0.1".LOGLEVEL: Set the logger's level filter, defaults to info in production-mode, debug in development-mode.PORT: Sets the port that this service will listen on. Defaults to 8080.This crate is intentionally somewhat prescriptive in how it templates a service and the interaction with add-on features such as Postgres (via SQLx).
Licensed under the BlueOak Model License 1.0.0 — Contributions via DCO 1.1