8 releases

0.2.0 May 25, 2023
0.1.6 May 19, 2023

#15 in #unofficial

28 downloads per month

MIT license

9KB
108 lines

zyte-api-rs

Allows access to the Zyte API proxy service.

This is an unofficial, unstable, unfinished crate. However normal usage with HTTP GET should work fine.

Prerequisites

Installation

cargo add zyte-api-rs

Example

use zyte_api_rs::ZyteApi;

#[tokio::main]
async fn get_google() {
    let zyte_api = ZyteApi::new("<MY_ZYTE_API_KEY>");

    // simple GET
    let response = zyte_api.get("https://www.google.com/").await.unwrap();

    // status_code is from http::Method
    if response.status_code.is_success() {
        println!("{}", response.http_response_body);
    }

    let response = zyte_api
        .post("https://httpbin.org/post")
        .unwrap()
        .text(r#"{"custname": "foobar"}"#)
        .send()
        .await
        .unwrap();

    if response.status_code.is_success() {
        println!("{}", response.http_response_body);
    }

}

Features

Requests

  • HTTP
    • GET
    • POST
      • httpResponseBody
      • httpResponseText
  • Browser
  • Headers

Responses

  • Normal Responses
  • Error Responses

Design Goals

Notes

  • The status code is actually an instance of http::StatusCode which allows more useful semantics such as status_code.is_success().

Dependencies

~5–19MB
~271K SLoC