spietika / restson-rust Goto Github PK
View Code? Open in Web Editor NEWEasy-to-use REST client for Rust programming language
License: MIT License
Easy-to-use REST client for Rust programming language
License: MIT License
I'd like to expose my client to Python so I'm trying to use milksnake to do so.
There seems to be a problem with cbindgen (used inside milksnake) which requires a fixed version of serde_derive (1.0.58).
But since restson explictly requires ^1.0.80
, the combination of both cannot be used.
Could it be possible to relax the exact dependencies, at least for serde_derive
? I think getting rid of the patch values should be enough:
hyper = "^0.12"
hyper-tls = "^0.3"
futures = "^0.1"
tokio-core = "^0.1"
serde = "^1.0"
serde_json = "^1.0"
serde_derive = "^1.0"
url = "^1.7"
log = "^0.4"
base64 = "^0.10"
letting cargo pick up the latest version. No need for a "required minimal patch version". And I believe this is the same as:
hyper = "0.12"
hyper-tls = "0.3"
futures = "0.1"
tokio-core = "0.1"
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
url = "1.7"
log = "0.4"
base64 = "0.10"
I noticed that the word "header" is mentioned nowhere on the README page, but there is a set_header() in restson-rust/src/blocking.rs:47
When I attempt:
let mut client = RestClient::builder()
.blocking(&url).set_header("zsessionid", zsessionid).unwrap();
I get
12 | .blocking(&url).set_header("zsessionid", zsessionid).unwrap();
| ^^^^^^^^^^ method not found in `Result<restson::blocking::RestClient, restson::Error>`
Are headers not-yet-implemented? I would like to troubleshoot this myself but I am not yet competent enough at Rust and am still working on executing my first successful header-containing HTTP request full-loop with strongly-typed result.
Are headers on the road-map?
Following the documentation in the section "JSON with array root element", I ended up with a lot of overhead having to deal with the enum having an array with one Vec element. Using a newtype struct seems to be a much easier way to deal with this, example:
#[derive(Serialize,Deserialize,Debug,Clone)]
struct Products ( pub Vec<Product> );
#[derive(Serialize,Deserialize,Debug,Clone)]
pub struct Product {
pub name: String,
[....]
}
impl RestPath<()> for Products { fn get_path(_: ()) -> Result<String,Error> { Ok(String::from("/api/objects/products"))}}
pub fn products(&self) -> Vec<Product> {
let mut client = RestClient::new("http://localhost:8080").unwrap();
client.get::<_, Products>(()).unwrap().0
}
This makes it much easier and cleaner to expose the actual contents of Product. I tried the suggested solution with enum before and had a hard time getting the actual contents having to deal with different enums types.
When doing requests, doing requests which expects the format of a object with a key which contains a list works fine, example:
{
"mylist": ["a", "b", "c"]
}
I cannot however do a requests which expects a list as the root object due to how serde works, example:
["a", "b", "c"]
This would help us in maintaining restson in Fedora.
Thanks in advance!
Should restson maybe have parameters to allow for using rustls?
I am posting to an API that responds with a JSON response that I want to deserialize into a struct.
I can't seem to find a way to get the response for posts, is it possible?
perhaps this is implemented and just needs documenting but i'm struggling to understand how to retrieve response headers when a request is successful.
the github api v3 paginates responses and populates the link header with information including the page number of the last available page (see: https://developer.github.com/v3/guides/traversing-with-pagination).
it's necessary to parse the response headers to understand what pages are available.
is there a way to access the response headers within the existing implementation?
The current implementation of post_capture seems to always encode the input data as JSON and pass that as the body. My REST server doesn't seem to support JSON input and expects POST data as form encoded. Is this maybe a distinction between the expected use cases of PUT and POST?
Needing a mutable reference means that only one request can be made at a time (?). Should that be fixed?
Client user should be able to set maximum allowed time for a HTTP request. If the maximum time is exceeded, the client should return timeout error.
Hyper guide for general timeouts: https://hyper.rs/guides/client/timeout/
I need to POST to a weird API where the response body is not json (but XML ๐ข).
Because of this I cannot use post_capture()
since it explicitly uses serde_json::from_str(body.as_str())
.
Could it be possible to get access to the (String
) body directly? Or maybe have the possibility to pass a different function to deserialize the data?
Thanks!!
Being AsRef<str>
allows passing many different kind of types, not just &str
.
PR pending...
Is there a way to get the response body when the server returns something other than 200 OK?
Have been using this library now for a few hours and seems to work very well and the implementation is simple so it's a joy to use. The examples were very useful!
I do need to do a DELETE request however and that does not seem to be implemented.
I am very new to Rust but it should be rather simple to implement.
I just wanted to tell you that if you do not intend implement this yourself soon, I might in a few weeks when I get more time.
I love using this package.
Main issue I have moving forward with it is that in our staging environment, several services do not have a valid ssl cert.
How should I disable the ssl certification check when using restson?
HyperError(hyper::Error(Connect, Os { code: -2146762487, kind: Other, message: "A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider." }))
For testing, I would like to disable this check.
Some REST API's require a User-Agent. Would it be a good idea to set a default?
While working on a PR, my editor formatted the whole file lib.rs
and I had to redo the edits by disabling autoformat.
rustfmt is now stable with 1.31: rustfmt 1.0.0-stable (4a4e5081 2018-11-29)
.
I need to post long (>16KB) string data to a REST endpoint.
Example program below.
Expected: the JSON data has both short_string and long_string values.
Actual:
println!("{}", j);
shows the object holding the correct values in full, leading me to believe this is something inside 'client.put'
Workaround? I'm using String
exclusively, not str
. Is there anything I can do?
use restson::RestClient;
use restson::RestPath;
use restson::Error;
use serde_derive::{Serialize};
#[derive(Serialize, Debug)]
pub struct MyJsonObject {
pub short_string: String,
pub long_string: String,
}
impl RestPath<()> for MyJsonObject {
fn get_path(_: ()) -> Result<String, Error> {
let uri_path = format!("/rest/end/point");
Ok(uri_path)
}
}
fn main() {
let short_string= std::iter::repeat("A").take(16360).collect::<String>();
let long_string = std::iter::repeat("Z").take(16364).collect::<String>();
let obj = MyJsonObject{
short_string,
long_string
};
let j = serde_json::to_string(&obj).unwrap();
println!("{}", j);
let mut client = RestClient::builder()
.blocking("http://localhost:8888/")
.unwrap();
client
.set_header("Content-Type", "application/json")
.unwrap();
match client.put((), &obj) {
Ok(r) => (println!("CREATED node : {:?}", r)),
Err(re) => ({
println!("FAILED node : {:?}", re);
}),
}
}
Is there an easy way to create a TLS connection? All of your examples are using http (non-TLS) connections. There is a function RestClient::with_builder
but it is private. How else can I provide a builder such that I can construct it with an HttpsConnector? Here is what I'd like to do:
let client = Client::builder().build(HttpsConnector::new());
RestClient::with_buidler("https://api.com", client)
It looks like you use an HttpsConnector here but there seems to be no way to match that case using any public constructors:
Line 260 in cee28ca
Hello!
Does this crate support simd_json library for json parsing? Seems it could be a good option for perfomance.
Simd json library is faster than other crates. To compare performance is better to see at json parsing benchmarking
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.