Comments (8)
I edited a checklist into the OP and filed individual issues to follow up on the remaining ones.
from rust-cookbook.
The cookbook is a bit heavy on HTTP patterns. There is no additional comments here that haven't been completed. I'm closing this issue.
from rust-cookbook.
Yes, this is a great idea, and non-trivial. Maybe some of these ideas can be split into multiple examples to avoid overwhelming.
What crate's would we need for the most basic example? reqwest, serde_json, url, others?
from rust-cookbook.
For my crate I use reqwest and json. I can't use serde due to the freedom in the api specification. Url is included as transitive dependency and re-exported through reqwest. It might be reasonable to provide examples with json and with serde as each has its usecases.
The bullet points should have a good size for a single example. The following is e.g. my code for GET, parsing and returning json. (I'm very open to improvements - it's the best I was able to write using the current docs)
fn get_json(&self, url: Url) -> Result<JsonValue, Box<Error>> {
println!("Loading: {:?}", &url);
let mut reponse = reqwest::get(url)?;
if !reponse.status().is_success() {
return Err(From::from(format!("Bad status code returned for request: {}",
reponse.status())));
}
let mut json_string = String::new();
reponse.read_to_string(&mut json_string)?;
Ok(json::parse(&json_string)?)
}
Another idea that comes to my mind is including an example using chrono for proper timestamp formatting.
from rust-cookbook.
Would you be able to elaborate on this part?
I can't use serde due to the freedom in the api specification.
This is what I would expect for analogous code using Serde:
extern crate serde_json;
use serde_json::Value;
fn get_json(&self, url: Url) -> Result<Value, Box<Error>> {
println!("Loading: {:?}", &url);
let response = reqwest::get(url)?;
if !response.status().is_success() {
return Err(From::from(format!("Bad status code returned for request: {}",
response.status())));
}
Ok(serde_json::from_reader(response)?)
}
from rust-cookbook.
I though serde was for deserializing into structs. But with that new option I'm definitely going to try serde! So there's likely no need for json-rust at all
from rust-cookbook.
@konstin a self-contained example about the size of the one in your previous post would be a fine addition.
from rust-cookbook.
Hi, I have implemented two relevant examples ("Query the GitHub API" idea taken from #24)
HTTP GET repo stargazers:
https://play.integer32.com/?gist=37adc825a9f373a3d2d38f0ab7a8672f&version=undefined
HTTP POST and DELETE: create a gist file and delete it
https://play.integer32.com/?gist=119d16cef32681c96a04058ba6c3514c&version=undefined
These still need cleanup and textual description etc.. Hopefully I will have some time tomorrow.
from rust-cookbook.
Related Issues (20)
- Indexing a map with a non-Copy structural key
- Replace lazy_static with once_cell
- Text refers to "Expand" button, actually it's "Show hidden lines"
- The header for the bitfield page is incorrect
- querying-the-web-api examples don't work due to missing user-agent-headers
- `GUI` create‘s introduce and contrast
- Use clap-derive instead of raw clap for argument parsing HOT 1
- 3.1 Decompress a tarball while removing a prefix from the paths with E0107 HOT 1
- Some documents are unavailable
- Mime crate badges show CSV's version HOT 1
- Missing (hard to find?) edit link to github
- Add recipe to building custom format-like macros
- Is this repo abandoned? HOT 5
- Bug: Sample Code Doesn't Work
- replace crossbeam's scoped threads with std's scoped threads
- Dead links in Mathematics section
- rusqlite first example does not compile HOT 2
- clap-basic.md is stale, wrong
- Clap basic got a wrong demo
- update Log Messages/Configure Logging sections HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-cookbook.