1 stable release

1.0.0 Nov 28, 2024

#1777 in Web programming

Download history 82/week @ 2024-11-22 49/week @ 2024-11-29 5/week @ 2024-12-06

136 downloads per month

Custom license

25KB
555 lines

fsolver

An easy to use, asynchronous wrapper for FlareSolverr.

Requirements

  • An instance of FlareSolverr running on your machine or a server. For more information on how to set up FlareSolverr, visit the official repository.

Installation

# With default features (only `async`)
cargo add fsolver

# With all features (`async` and `blocking`)
cargo add fsolver -F all

# Only blocking
cargo add fsolver --no-default-features -F blocking

Usage

For more info, visit the documentation.

Async

use fsolver::FlareSolverrAsync;

// Setup the flare solver instance with default settings
let solver = FlareSolverrAsync::new(None, None, None, None, None)
    .await
    .unwrap();

// With custom ip and port
let solver = FlareSolverrAsync::new(Some("127.0.0.1"), Some("5050"), None, None, None)
    .await
    .unwrap();

// Use different http schema
use fsolver::HttpSchema;
let solver = FlareSolverrAsync::new(None, None, Some(HttpSchema::Http), None, None)
    .await
    .unwrap();

// If you want some additional headers
use std::collections::HashMap;

let mut headers = HashMap::new();
headers.insert("User-Agent".to_string(), "Mozilla/5.0 (X11; Linux x86_64)".to_string());

let solver = FlareSolverrAsync::new(None, None, None, Some(headers), None)
    .await
    .unwrap();

// When (for whatever the reason) flaresolverr changes /v1 endpoint
let solver = FlareSolverrAsync::new(None, None, None, None, Some("v2"))
    .await
    .unwrap();

// List all sessions
let sessions: Vec<String> = solver.sessions().await.unwrap();

// List sessions and get response raw
let sessions: SessionListResponse = solver.sessions().await.unwrap();

// Create a new session with a random UUID
let session_id = solver.create_session(None).await.unwrap();

// Create a new session with a custom name/ID
let session_id = "myses";
let session_id = solver.create_session(Some(session_id)).await.unwrap();

// Delete/destroy a session
solver.destroy_session(session_id).await.unwrap();

// Get request
use fsolver::RequestGet;

let session_id = solverr.create_session(None).await.unwrap();
let get_request_params = RequestGet::new(
    "https://example.com".into(),
    Some(session_id),
    None,
    None,
    None,
    None,
    None,
);
let response: GetPostRequestResponse = solver.request_get(get_request_params).await.unwrap()

// Post request
use fsolver::RequestPost;

let post_request_params = RequestPost::new_empty("https://example.com".to_string(), "a=b&c=d".to_string())

let response: GetPostRequestResponse = solver.request_post(post_request_params).await.unwrap();

Blocking

use fsolver::FlareSolverrBlocking;

// Yep, just that. All functions are the same. Call functions without await.

Dependencies

~4–15MB
~199K SLoC