pub struct Client { /* private fields */ }Expand description
Client to submit a request to a Hcaptcha validation endpoint.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new() -> Client
pub fn new() -> Client
Create a new Hcaptcha Client to connect with the default Hcaptcha siteverify API endpoint specified in VERIFY_URL.
§Example
Initialise client to connect to default API endpoint.
use hcaptcha_no_wasm::Client;
let client = Client::new();§Panic
If the default API url constant is corrupted the function with will panic.
Sourcepub fn new_with(url: &str) -> Result<Client, ParseError>
pub fn new_with(url: &str) -> Result<Client, ParseError>
Create a new Hcaptcha Client and specify the url for the API.
Specify the url for the hcaptcha API.
§Example
Initialise client to connect to custom Hcaptcha API
use hcaptcha_no_wasm::Client;
use url::Url;
let url = "https://domain.com/siteverify";
let _client = Client::new_with(url);Sourcepub fn set_url(self, url: &str) -> Result<Self, Error>
pub fn set_url(self, url: &str) -> Result<Self, Error>
Set the url.
Specify the url for the hcaptcha API. This method is useful during testing to provide a mock url.
§Example
Initialise client to connect to custom Hcaptcha API
use hcaptcha_no_wasm::Client;
use url::Url;
let url = "https://domain.com/siteverify";
let client = Client::new()
.set_url(url)?;Sourcepub async fn verify_client_response(
self,
request: Request,
) -> Result<Response, Error>
👎Deprecated since 3.0.0: please use verify instead
pub async fn verify_client_response( self, request: Request, ) -> Result<Response, Error>
verify insteadVerify the client token with the Hcaptcha service API.
Call the Hcaptcha api and provide a Request struct.
§Inputs
Request contains the required and optional fields for the Hcaptcha API. The required fields include the response code to validate and the secret key.
§Outputs
This method returns Response if successful and Error if unsuccessful.
§Example
use hcaptcha_no_wasm::{Client, Request};
let secret = get_your_secret(); // your secret key
let captcha = get_captcha(); // user's token
let request = Request::new(&secret, captcha)?;
let client = Client::new();
let response = client.verify_client_response(request).await?;
let score = response.score();
let score_reasons = response.score_reason();
§Logging
If the trace feature is enabled a debug level span is set for the
method and an event logs the response.
Sourcepub async fn verify(self, request: Request) -> Result<Response, Error>
pub async fn verify(self, request: Request) -> Result<Response, Error>
Verify the client token with the Hcaptcha service API.
Call the Hcaptcha api and provide a Request struct.
§Inputs
Request contains the required and optional fields for the Hcaptcha API. The required fields include the response code to validate and the secret key.
§Outputs
This method returns Response if successful and Error if unsuccessful.
§Example
use hcaptcha_no_wasm::{Client, Request};
let secret = get_your_secret(); // your secret key
let captcha = get_captcha(); // user's token
let request = Request::new(&secret, captcha)?;
let client = Client::new();
let response = client.verify(request).await?;
let score = response.score();
let score_reasons = response.score_reason();
§Logging
If the trace feature is enabled a debug level span is set for the
method and an event logs the response.