7 unstable releases
0.4.1 | Jan 25, 2023 |
---|---|
0.4.0 | Sep 13, 2022 |
0.3.1 | Jan 17, 2022 |
0.3.0 | May 17, 2021 |
0.1.0 | May 10, 2021 |
#41 in #php
32KB
651 lines
espocrm-rs
A Rust implementation of the EspoCRM PHP API Client. You can find this client here.
For information on how to use this crate, refer to docs.rs
Dependencies
Refer to crates.io
Licence
espocrm-rs
is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT, and COPYRIGHT for details.
lib.rs
:
espocrm-rs
The espocrm-rs
crate provides an API Client for EspoCRM. This client is based on the official PHP API client provided by the EspoCRM team.
You can find this client here.
Getting started
To get started you'll have to provide the URL where EspoCRM is located at. You will also have to set the way you want to authenticate with EspoCRM. This can be done in one of the following ways:
- Username+Password
- API Key
- HMAC (Recommended)
The following example creates an EspoApiClient with HMAC authorization
use espocrm_rs::EspoApiClient;
let client = EspoApiClient::new("https://espocrm.example.com")
.set_api_key("Your API Key here")
.set_secret_key("Your API Secret")
.build();
The following example creates an EspoApiClient with API Key authorization
use espocrm_rs::EspoApiClient;
let client = EspoApiClient::new("https://espocrm.example.com")
.set_api_key("Your API Key here")
.build();
The following example creates an EspoApiClient with Username+Password authorization. This is highly discouraged!
use espocrm_rs::EspoApiClient;
let client = EspoApiClient::new("https://espocrm.example.com")
.set_username("Your Username here")
.set_password("Your Password here")
.build();
Making a GET request
To make a request, you need to know a couple things:
- The request method to use
- On what to perform the request
- Optionally, any data needed for the request
Most of these things are laid out pretty well in the EspoCRM API documentation here
use espocrm_rs::{EspoApiClient, Params, Where, FilterType, Value, NoGeneric, Method};
let params = Params::default()
.set_offset(0)
.set_where(vec![
Where {
r#type: FilterType::IsTrue,
attribute: "exampleField".to_string(),
value: None
},
Where {
r#type: FilterType::ArrayAnyOf,
attribute: "exampleField2".to_string(),
value: Some(Value::array(vec![
Value::str("a"),
Value::str("b"),
Value::str("c")
]))
}
])
.build();
let client = EspoApiClient::new("https://espocrm.example.com")
.set_secret_key("Your Secret Key")
.set_api_key("Your api key")
.build();
let result = client.request::<NoGeneric, &str>(Method::Get, "Contact", Some(params), None);
Making a POST, PUT or DELETE request
These are all similar in working. They'll serialize your data into json using Serde's serialize trait
use espocrm_rs::{EspoApiClient, Method};
use serde::Serialize;
#[derive(Serialize, Clone)]
struct MyData {
some_value: String,
some_other_value: i64
}
let client = EspoApiClient::new("https://espocrm.example.com")
.set_secret_key("Your Secret Key")
.set_api_key("Your api key")
.build();
let data = MyData {
some_value: "value".to_string(),
some_other_value: 10
};
let result = client.request(Method::Post, "Contact", None, Some(data));
Dependencies
~5–16MB
~225K SLoC