committed by
Sean McArthur
parent
81e0f1ff2a
commit
cf8944a0f0
@@ -1,16 +1,11 @@
|
||||
#![deny(warnings)]
|
||||
|
||||
extern crate futures;
|
||||
extern crate reqwest;
|
||||
extern crate tokio;
|
||||
|
||||
use std::mem;
|
||||
use std::io::{self, Cursor};
|
||||
use futures::{Future, Stream};
|
||||
use reqwest::r#async::{Client, Decoder};
|
||||
use std::io::{self, Cursor};
|
||||
use std::mem;
|
||||
|
||||
|
||||
fn fetch() -> impl Future<Item=(), Error=()> {
|
||||
fn fetch() -> impl Future<Item = (), Error = ()> {
|
||||
Client::new()
|
||||
.get("https://hyper.rs")
|
||||
.send()
|
||||
@@ -23,10 +18,9 @@ fn fetch() -> impl Future<Item=(), Error=()> {
|
||||
.map_err(|err| println!("request error: {}", err))
|
||||
.map(|body| {
|
||||
let mut body = Cursor::new(body);
|
||||
let _ = io::copy(&mut body, &mut io::stdout())
|
||||
.map_err(|err| {
|
||||
println!("stdout error: {}", err);
|
||||
});
|
||||
let _ = io::copy(&mut body, &mut io::stdout()).map_err(|err| {
|
||||
println!("stdout error: {}", err);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
#![deny(warnings)]
|
||||
|
||||
extern crate futures;
|
||||
extern crate reqwest;
|
||||
extern crate tokio;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
|
||||
use futures::Future;
|
||||
use reqwest::r#async::{Client, Response};
|
||||
use serde::Deserialize;
|
||||
@@ -21,27 +15,18 @@ struct SlideshowContainer {
|
||||
slideshow: Slideshow,
|
||||
}
|
||||
|
||||
fn fetch() -> impl Future<Item=(), Error=()> {
|
||||
fn fetch() -> impl Future<Item = (), Error = ()> {
|
||||
let client = Client::new();
|
||||
|
||||
let json = |mut res : Response | {
|
||||
res.json::<SlideshowContainer>()
|
||||
};
|
||||
let json = |mut res: Response| res.json::<SlideshowContainer>();
|
||||
|
||||
let request1 =
|
||||
client
|
||||
.get("https://httpbin.org/json")
|
||||
.send()
|
||||
.and_then(json);
|
||||
let request1 = client.get("https://httpbin.org/json").send().and_then(json);
|
||||
|
||||
let request2 =
|
||||
client
|
||||
.get("https://httpbin.org/json")
|
||||
.send()
|
||||
.and_then(json);
|
||||
let request2 = client.get("https://httpbin.org/json").send().and_then(json);
|
||||
|
||||
request1.join(request2)
|
||||
.map(|(res1, res2)|{
|
||||
request1
|
||||
.join(request2)
|
||||
.map(|(res1, res2)| {
|
||||
println!("{:?}", res1);
|
||||
println!("{:?}", res2);
|
||||
})
|
||||
|
||||
@@ -1,18 +1,11 @@
|
||||
#![deny(warnings)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate futures;
|
||||
extern crate bytes;
|
||||
extern crate reqwest;
|
||||
extern crate tokio;
|
||||
extern crate tokio_threadpool;
|
||||
|
||||
use std::io::{self, Cursor};
|
||||
use std::mem;
|
||||
use std::path::Path;
|
||||
|
||||
use bytes::Bytes;
|
||||
use futures::{Async, Future, Poll, Stream};
|
||||
use futures::{try_ready, Async, Future, Poll, Stream};
|
||||
use reqwest::r#async::{Client, Decoder};
|
||||
use tokio::fs::File;
|
||||
use tokio::io::AsyncRead;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
extern crate reqwest;
|
||||
|
||||
fn main() {
|
||||
reqwest::Client::new()
|
||||
.post("http://www.baidu.com")
|
||||
|
||||
@@ -3,19 +3,16 @@
|
||||
//! This is useful for some ad-hoc experiments and situations when you don't
|
||||
//! really care about the structure of the JSON and just need to display it or
|
||||
//! process it at runtime.
|
||||
extern crate reqwest;
|
||||
#[macro_use] extern crate serde_json;
|
||||
use serde_json::json;
|
||||
|
||||
fn main() -> Result<(), reqwest::Error> {
|
||||
let echo_json: serde_json::Value = reqwest::Client::new()
|
||||
.post("https://jsonplaceholder.typicode.com/posts")
|
||||
.json(
|
||||
&json!({
|
||||
"title": "Reqwest.rs",
|
||||
"body": "https://docs.rs/reqwest",
|
||||
"userId": 1
|
||||
})
|
||||
)
|
||||
.json(&json!({
|
||||
"title": "Reqwest.rs",
|
||||
"body": "https://docs.rs/reqwest",
|
||||
"userId": 1
|
||||
}))
|
||||
.send()?
|
||||
.json()?;
|
||||
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
//! In contrast to the arbitrary JSON example, this brings up the full power of
|
||||
//! Rust compile-time type system guaranties though it requires a little bit
|
||||
//! more code.
|
||||
extern crate reqwest;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -23,7 +20,7 @@ fn main() -> Result<(), reqwest::Error> {
|
||||
id: None,
|
||||
title: "Reqwest.rs".into(),
|
||||
body: "https://docs.rs/reqwest".into(),
|
||||
user_id: 1
|
||||
user_id: 1,
|
||||
};
|
||||
let new_post: Post = reqwest::Client::new()
|
||||
.post("https://jsonplaceholder.typicode.com/posts")
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
|
||||
//! `cargo run --example simple`
|
||||
|
||||
extern crate reqwest;
|
||||
extern crate env_logger;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
env_logger::init();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user