9 releases (5 breaking)

Uses old Rust 2015

0.6.0 Nov 22, 2017
0.5.0 Jan 11, 2017
0.4.1 Aug 23, 2016
0.4.0 Jul 23, 2016
0.1.2 Mar 23, 2015

#4 in #iron-framework

Download history 686/week @ 2024-07-22 640/week @ 2024-07-29 616/week @ 2024-08-05 1023/week @ 2024-08-12 698/week @ 2024-08-19 708/week @ 2024-08-26 810/week @ 2024-09-02 606/week @ 2024-09-09 646/week @ 2024-09-16 757/week @ 2024-09-23 656/week @ 2024-09-30 247/week @ 2024-10-07 634/week @ 2024-10-14 1052/week @ 2024-10-21 610/week @ 2024-10-28 565/week @ 2024-11-04

2,887 downloads per month
Used in 31 crates (20 directly)

MIT license

9KB
92 lines

urlencoded Build Status

URL Encoded middleware for the Iron web framework. Decode URL Encoded data from GET request queries and POST request bodies.

Example

This example shows how to use urlencoded to parse GET request parameters.

extern crate iron;
extern crate urlencoded;

use iron::prelude::*;
use iron::status;
use urlencoded::UrlEncodedQuery;

fn log_params(req: &mut Request) -> IronResult<Response> {
    // Extract the decoded data as hashmap, using the UrlEncodedQuery plugin.
    match req.get_ref::<UrlEncodedQuery>() {
        Ok(ref hashmap) => println!("Parsed GET request query string:\n {:?}", hashmap),
        Err(ref e) => println!("{:?}", e)
    };

    Ok(Response::with((status::Ok, "Hello!")))
}

// Test out the server with `curl -i "http://localhost:3000/?name=franklin&name=trevor"`
fn main() {
    Iron::new(log_params).http("127.0.0.1:3000").unwrap();
}

Overview

urlencoded is a part of Iron's core bundle.

  • Parses a URL query string into a HashMaps that maps String representations of keys onto a Vec of String values.
  • Values are stored in a Vec to ensure that no information is lost if a key appears multiple times. The query string a=b&a=c will result in a mapping from a to [b, c].
  • Parses POST request bodies for web form data (MIME type: application/x-www-form-urlencoded).

Installation

If you're using Cargo to manage dependencies, just add urlencoded to Cargo.toml:

[dependencies.urlencoded]
version = "*"

Otherwise, cargo build, and the rlib will be in your target directory.

Documentation

Along with the online documentation, you can build a local copy with cargo doc.

Examples

Get Help

One of us (@reem, @zzmp, @theptrk, @mcreinhard) is usually on #iron on the mozilla irc. Come say hi and ask any questions you might have. We are also usually on #rust and #rust-webdev.

Dependencies

~6MB
~130K SLoC