Skip to content
This repository was archived by the owner on Jun 21, 2020. It is now read-only.
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<<<<<<< HEAD
# Generated by Cargo
# will have compiled files and executables
/target/
Expand All @@ -9,8 +8,3 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk
=======
/target
**/*.rs.bk
Cargo.lock
>>>>>>> Initial commit
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# http-service
<h1 align="center">http-service</h1>
<div align="center">
<strong>
Types and traits to help you implement your own HTTP server
</strong>
</div>

<br />


[![build status][1]][2]

Types and traits giving an interface between low-level http server implementations
and services that use them. The interface is based on the `std::futures` API.

## License

Expand Down
31 changes: 31 additions & 0 deletions examples/simple_response.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#![feature(futures_api, async_await, await_macro, existential_type)]

use futures::future::{self, FutureObj};
use http_service::{HttpService, Response};

struct Server {
message: Vec<u8>,
}

impl Server {
fn create(message: Vec<u8>) -> Server {
Server { message }
}
}

impl HttpService for Server {
type Connection = ();
type ConnectionFuture = future::Ready<Result<(), std::io::Error>>;
type Fut = FutureObj<'static, Result<http_service::Response, std::io::Error>>;

fn connect(&self) -> Self::ConnectionFuture {
future::ok(())
}

fn respond(&self, _conn: &mut (), _req: http_service::Request) -> Self::Fut {
let message = self.message.clone();
FutureObj::new(Box::new(async move {
Ok(Response::new(http_service::Body::from(message)))
}))
}
}