This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Corgi | |
- name: Malamute |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
|- _cobalt.yml | |
|- _layouts | |
| |- default.liquid | |
|- _includes | |
| |- header.liquid | |
|- _data | |
| |- movies.json | |
|- _sass | |
| |- base.scss |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let resp = ureq::post("https://myapi.example.com/ingest") | |
.set("X-My-Header", "Secret") | |
.send_json(serde_json::json!({ | |
"name": "martin", | |
"rust": true | |
})); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::Read; | |
use curl::easy::Easy; | |
fn main() { | |
let mut data = "this is the body".as_bytes(); | |
let mut easy = Easy::new(); | |
easy.url("http://www.example.com/upload").unwrap(); | |
easy.post(true).unwrap(); | |
easy.post_field_size(data.len() as u64).unwrap(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use futures::future::BoxFuture; | |
use surf::middleware::{Next, Middleware, Request, Response, HttpClient}; | |
use std::time; | |
/// Log each request's duration | |
#[derive(Debug)] | |
pub struct Logger; | |
impl<C: HttpClient> Middleware<C> for Logger { | |
fn handle<'a>( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use isahc::prelude::*; | |
fn main() -> Result<(), isahc::Error> { | |
// Send a GET request and wait for the response headers. | |
// Must be `mut` so we can read the response body. | |
let mut response = isahc::get("http://example.org")?; | |
// Print some basic info about the response to standard output. | |
println!("Status: {}", response.status()); | |
println!("Headers: {:#?}", response.headers()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let client = Client::new(); | |
// Parse an `http::Uri`... | |
let uri = "http://httpbin.org/ip".parse()?; | |
// Await the response... | |
let resp = client.get(uri).await?; | |
println!("Response: {}", resp.status()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. GET | |
let body = reqwest::get("https://www.rust-lang.org") | |
.await? | |
.text() | |
.await?; | |
println!("body = {:?}", body); | |
// 2. POST | |
let client = reqwest::Client::new(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::thread; | |
use std::time::Duration; | |
fn main() { | |
// 1. create a new thread | |
thread::spawn(|| { | |
for i in 1..10 { | |
println!("thread: number {}!", i); | |
thread::sleep(Duration::from_millis(100)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func f(from string) { | |
for i := 0; i < 3; i++ { | |
fmt.Println(from, ":", i) |