pub struct Server { /* private fields */ }Expand description
jsonrpc http server instance
Implementations§
Source§impl Server
impl Server
Sourcepub fn address(&self) -> &SocketAddr
pub fn address(&self) -> &SocketAddr
Returns address of this server
Sourcepub fn wait(self)
pub fn wait(self)
Will block, waiting for the server to finish.
Examples found in repository?
examples/http_async.rs (line 15)
4fn main() {
5 let mut io = IoHandler::default();
6 io.add_method("say_hello", |_params| {
7 futures::finished(Value::String("hello".to_owned()))
8 });
9
10 let server = ServerBuilder::new(io)
11 .cors(DomainsValidation::AllowOnly(vec![AccessControlAllowOrigin::Null]))
12 .start_http(&"127.0.0.1:3030".parse().unwrap())
13 .expect("Unable to start RPC server");
14
15 server.wait();
16}More examples
examples/server.rs (line 15)
4fn main() {
5 let mut io = IoHandler::default();
6 io.add_method("say_hello", |_params: Params| Ok(Value::String("hello".to_string())));
7
8 let server = ServerBuilder::new(io)
9 .threads(3)
10 .rest_api(RestApi::Unsecure)
11 .cors(DomainsValidation::AllowOnly(vec![AccessControlAllowOrigin::Any]))
12 .start_http(&"127.0.0.1:3030".parse().unwrap())
13 .expect("Unable to start RPC server");
14
15 server.wait();
16}examples/http_middleware.rs (line 24)
5fn main() {
6 let mut io = IoHandler::default();
7 io.add_method("say_hello", |_params| {
8 futures::finished(Value::String("hello".to_owned()))
9 });
10
11 let server = ServerBuilder::new(io)
12 .cors(DomainsValidation::AllowOnly(vec![AccessControlAllowOrigin::Null]))
13 .request_middleware(|request: hyper::Request<hyper::Body>| {
14 if request.uri() == "/status" {
15 Response::ok("Server running OK.").into()
16 } else {
17 request.into()
18 }
19 })
20 .rest_api(RestApi::Unsecure)
21 .start_http(&"127.0.0.1:3030".parse().unwrap())
22 .expect("Unable to start RPC server");
23
24 server.wait();
25}examples/http_meta.rs (line 40)
11fn main() {
12 let mut io = MetaIoHandler::default();
13
14 io.add_method_with_meta("say_hello", |_params: Params, meta: Meta| {
15 let auth = meta.auth.unwrap_or_else(String::new);
16 if auth.as_str() == "let-me-in" {
17 Ok(Value::String("Hello World!".to_owned()))
18 } else {
19 Ok(Value::String(
20 "Please send a valid Bearer token in Authorization header.".to_owned(),
21 ))
22 }
23 });
24
25 let server = ServerBuilder::new(io)
26 .cors_allow_headers(AccessControlAllowHeaders::Only(vec!["Authorization".to_owned()]))
27 .rest_api(RestApi::Unsecure)
28 // You can also implement `MetaExtractor` trait and pass a struct here.
29 .meta_extractor(|req: &hyper::Request<hyper::Body>| {
30 let auth = req
31 .headers()
32 .get(hyper::header::AUTHORIZATION)
33 .map(|h| h.to_str().unwrap_or("").to_owned());
34
35 Meta { auth }
36 })
37 .start_http(&"127.0.0.1:3030".parse().unwrap())
38 .expect("Unable to start RPC server");
39
40 server.wait();
41}Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Server
impl !UnwindSafe for Server
impl Freeze for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl UnsafeUnpin for Server
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more