Coder Social home page Coder Social logo

restson-rust's People

Contributors

jcaesar avatar kaiha avatar nbigaouette-eai avatar silwol avatar spietika avatar srwalter avatar suuvor avatar tuetuopay avatar wose avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

restson-rust's Issues

Compilation issue with serde_derive

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"

Adding header using set_header() not working

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?

Documentation: Use newtype for JSON with array root element

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.

Add support for lists as the root object

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"]

expose response headers on successful request/response

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?

POST and form encoding

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?

Response Body HttpError

Is there a way to get the response body when the server returns something other than 200 OK?

Add support for DELETE requests

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.

How should restson-rust users disable check ssl certification?

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.

Default User-Agent?

Some REST API's require a User-Agent. Would it be a good idea to set a default?

Long String values vanish or malform JSON

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:

  • The longest possible string is 16361 bytes.
  • 16362 does something strange and it serialises as date, without a label creating malformed JSON.
  • Greater than 16363 removes the value from the JSON, breaking the endpoint.

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);
        }),
    }
}

How to use a TLS connection?

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:

Client::builder().build(HttpsConnector::new())

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.