Skip to content

Commit

Permalink
(init)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkylerLipthay committed Jul 8, 2015
0 parents commit 20d97cd
Show file tree
Hide file tree
Showing 7 changed files with 586 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
Cargo.lock
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Contributing

**params** uses the same conventions as **[Iron](https://github.com/iron/iron)**.

### Overview

* Fork body-parser to your own account
* Create a feature branch, namespaced by.
* bug/...
* feat/...
* test/...
* doc/...
* refactor/...
* Make commits to your feature branch. Prefix each commit like so:
* (feat) Added a new feature
* (fix) Fixed inconsistent tests [Fixes #0]
* (refactor) ...
* (cleanup) ...
* (test) ...
* (doc) ...
* Make a pull request with your changes directly to master. Include a
description of your changes.
* Wait for one of the reviewers to look at your code and either merge it or
give feedback which you should adapt to.

#### Thank you for contributing!
17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "params"
version = "0.0.1"
authors = ["Skyler Lipthay <[email protected]>"]
description = "A multi-source request parameters parser for Iron."
readme = "README.md"
license = "MIT"
repository = "https://github.com/iron/params"
documentation = "http://ironframework.io/doc/params/index.html"

[dependencies]
bodyparser = "*"
formdata = { git = "https://github.com/SkylerLipthay/formdata" }
iron = "*"
plugin = "*"
rustc-serialize = "*"
urlencoded = "*"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 iron

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# params

A plugin for the [Iron](https://github.com/iron/iron) web framework that parses parameters from incoming requests from the following sources:

* JSON data (`Content-Type: application/json`)
* URL-encoded GET parameters
* URL-encoded `Content-Type: application/x-www-form-urlencoded` parameters
* Multipart form data (`Content-Type: multipart/form-data`)

See `examples/params.rs` for details.
36 changes: 36 additions & 0 deletions examples/params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
extern crate iron;
extern crate params;

use iron::prelude::*;
use iron::status;
use params::Params;

fn handle(req: &mut Request) -> IronResult<Response> {
println!("{:?}", req.get_ref::<Params>());
Ok(Response::with(status::Ok))
}

// Execute the following cURL requests and watch your terminal for the parsed parameters.
//
// `curl -i "localhost:3000" -H "Content-Type: application/json" -d '{"name":"jason","age":2}'`
// => Ok({"age": U64(2), "name": String("jason")})
//
// `curl -i -X POST "http://localhost:3000/" --data "fruit=apple&name=iron&fruit=pear"`
// => Ok({"fruit": String("pear"), "name": String("iron")})
//
// `curl -i "http://localhost:3000/?x\[\]=1&x\[\]=2" -F "images[]=@/path/to/file.jpg"`
// => Ok({
// "images": Array([File(UploadedFile {
// path: "/tmp/path/to/file.jpg",
// filename: Some("file.jpg"),
// content_type: Mime(Image, Jpeg, []),
// size: 1234
// })]),
// "x": Array([String("1"), String("2")])
// })
//
// `curl -i -X POST "http://localhost:3000/" --data "x[][]=2"`
// => Err(InvalidPath)
fn main() {
Iron::new(Chain::new(handle)).http("localhost:3000").unwrap();
}
Loading

0 comments on commit 20d97cd

Please sign in to comment.