Crate iron

Source
Expand description

The main crate for Iron.

§Overview

Iron is a high level web framework built in and for Rust, built on hyper. Iron is designed to take advantage of Rust’s greatest features - its excellent type system and principled approach to ownership in both single threaded and multi threaded contexts.

Iron is highly concurrent and can scale horizontally on more machines behind a load balancer or by running more threads on a more powerful machine. Iron avoids the bottlenecks encountered in highly concurrent code by avoiding shared writes and locking in the core framework.

§Hello World

extern crate iron;

use iron::prelude::*;
use iron::status;

fn main() {
    Iron::new(|_: &mut Request| {
        Ok(Response::with((status::Ok, "Hello World!")))
    }).http("localhost:3000").unwrap();
}

§Design Philosophy

Iron is meant to be as extensible and pluggable as possible; Iron’s core is concentrated and avoids unnecessary features by leaving them to middleware, plugins, and modifiers.

Middleware, Plugins, and Modifiers are the main ways to extend Iron with new functionality. Most extensions that would be provided by middleware in other web frameworks are instead addressed by the much simpler Modifier and Plugin systems.

Modifiers allow external code to manipulate Requests and Response in an ergonomic fashion, allowing third-party extensions to get the same treatment as modifiers defined in Iron itself. Plugins allow for lazily-evaluated, automatically cached extensions to Requests and Responses, perfect for parsing, accessing, and otherwise lazily manipulating an http connection.

Middleware are only used when it is necessary to modify the control flow of a Request flow, hijack the entire handling of a Request, check an incoming Request, or to do final post-processing. This covers areas such as routing, mounting, static asset serving, final template rendering, authentication, and logging.

Iron comes with only basic modifiers for setting the status, body, and various headers, and the infrastructure for creating modifiers, plugins, and middleware. No plugins or middleware are bundled with Iron.

Re-exports§

Modules§

  • Iron’s error type and associated utilities.
  • Headers container, and common header fields.
  • HTTP Methods
  • This module contains Iron’s middleware and handler system, the fundamental building blocks for handling HTTP requests and generating responses.
  • Re-exporting the mime crate, for convenience.
  • Re-exports from the Modifier crate.
  • This module defines a series of convenience modifiers for changing Responses.
  • A module meant to be glob imported when using Iron.
  • Iron’s HTTP Request representation and associated methods.
  • Iron’s HTTP Response representation and associated methods.
  • Status Codes
  • Re-exports from the TypeMap crate.
  • Re-exports from the url crate.

Macros§

  • Unwrap the given Option or return a Ok(Response::new()) with the given modifier. The default modifier is status::BadRequest.
  • Like try!(), but wraps the error value in IronError. To be used in request handlers.

Structs§

  • A map of header fields on requests and responses.
  • The primary entrance point to Iron, a struct to instantiate a new server.
  • A listening server, which can later be closed.
  • Protocol used to serve content.
  • A settings struct containing a set of timeouts which can be applied to a server.
  • A map keyed by types.

Traits§

  • Error is a trait representing the basic expectations for error values, i.e., values of type E in Result<T, E>.
  • An interface for plugins that cache values between calls.
  • A trait providing the set and set_mut methods for all types.

Type Aliases§

  • The Result alias used throughout Iron and in clients of Iron.