Skip to content

Commit

Permalink
Designing the API chris-morgan#9
Browse files Browse the repository at this point in the history
  • Loading branch information
flaper87 committed Oct 5, 2013
1 parent a5c4eb3 commit 5bd694d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/libhttp/client/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use std::rt::io::net::tcp::TcpStream;
use std::rt::io::net::ip::{SocketAddr, Ipv4Addr};

use method;
use client::request::RequestWriter;
use client::response::ResponseReader;

// TODO: Implement a Response trait

pub fn request(method: method::Method, url: ~str)
-> Result<ResponseReader<TcpStream>, ~RequestWriter<TcpStream>>{

let url = FromStr::from_str(url).expect("Uh oh, that's *really* badly broken!");
let mut request = ~RequestWriter::new(method, url);

// TODO: https://github.com/chris-morgan/rust-http/issues/10
// Temporary measure, as hostname lookup is not yet supported in std::rt::io.
request.remote_addr = Some(SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 8001 });
request.read_response()
}

pub fn get(url: ~str)
-> Result<ResponseReader<TcpStream>, ~RequestWriter<TcpStream>> {

request(method::Get, url)
}

// TODO: Add body
pub fn post(url: ~str)
-> Result<ResponseReader<TcpStream>, ~RequestWriter<TcpStream>> {

request(method::Post, url)
}

// TODO: Add body
pub fn patch(url: ~str)
-> Result<ResponseReader<TcpStream>, ~RequestWriter<TcpStream>> {

request(method::Patch, url)
}

// TODO: Add body
pub fn put(url: ~str)
-> Result<ResponseReader<TcpStream>, ~RequestWriter<TcpStream>> {

request(method::Put, url)
}

pub fn delete(url: ~str)
-> Result<ResponseReader<TcpStream>, ~RequestWriter<TcpStream>> {

request(method::Delete, url)
}
1 change: 1 addition & 0 deletions src/libhttp/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub use self::request::RequestWriter;
pub use self::response::ResponseReader;

pub mod api;
pub mod request;
pub mod response;

0 comments on commit 5bd694d

Please sign in to comment.