Skip to content

Commit 80f6326

Browse files
shimatar0irevoire
andauthored
Feat trait to make clients customizable (#459)
* Feat trait to make clients customizable * remove the uneeded Http bound on the tasks and key * Fix incorrect type specification * Remove delete unused module * Change the return value of the request function * Fix return value * Add cliant structure correspondence specifying IsahcClient * Remove unnecessary specification * Fix typo, unnecessary comment out * Fix macro to generate IndexConfig * Fix task_info test * Fix typo * Fix test * Fix settings.rs in example * Change request mod to public * Add stream_request to HttpClient * Add send and sync trait * Change request method calls in setting.rs to use http_client * Change request method calls in client.rs to use http_client * Change request method calls in indexes.rs to use http_client * Change request method calls in dumps.rs to use http_client * Fix async_trait to have Send trait for wasm32 build * Fix async trait in index config and macro code * Fix clippy warning(never used) * Fix cli-app example * Fix test * Add example of using reqwest for http_client * Fix typo * Fix to put underscore on unused variables in example * Fix Default to derive * Fix to arrangement client methods * Change isahc enables optional flag * Change functional flags for code that depends on isahc * Fix cargo check pass in the no-default-features * Fix unused import * Fix formatting * Change disable default-features in the example * Fix format * Add client and index types that can be used without specifying an HTTP Trait when in isahc(default) mode * Remove unused function * Fix to use WebSysClient for wasm * Add prelude * Fix example to use prelude * Fix prelude * Add to README text about custom HttpClient and link to example. * Feat trait to make clients customizable * remove the uneeded Http bound on the tasks and key * Fix incorrect type specification * Remove delete unused module * Change the return value of the request function * Fix return value * Add cliant structure correspondence specifying IsahcClient * Remove unnecessary specification * Fix typo, unnecessary comment out * Fix macro to generate IndexConfig * Fix task_info test * Fix typo * Fix test * Fix settings.rs in example * Change request mod to public * Add stream_request to HttpClient * Add send and sync trait * Change request method calls in setting.rs to use http_client * Change request method calls in client.rs to use http_client * Change request method calls in indexes.rs to use http_client * Change request method calls in dumps.rs to use http_client * Fix async_trait to have Send trait for wasm32 build * Fix async trait in index config and macro code * Fix clippy warning(never used) * Fix cli-app example * Fix test * Add example of using reqwest for http_client * Fix typo * Fix to put underscore on unused variables in example * Fix Default to derive * Fix to arrangement client methods * Change isahc enables optional flag * Change functional flags for code that depends on isahc * Fix cargo check pass in the no-default-features * Fix unused import * Fix formatting * Change disable default-features in the example * Fix format * Add client and index types that can be used without specifying an HTTP Trait when in isahc(default) mode * Remove unused function * Fix to use WebSysClient for wasm * Add prelude * Fix example to use prelude * Fix prelude * Add to README text about custom HttpClient and link to example. * Fix rebase commit * Add support for new functions * merge with main * make the Client and Index uses our IsahcClient by default * fix all doctests * fmt * get rids of the breaking prelude * makes clippy happy * implement serialize myself * make the cargo check --no-default-features works * adds a check in the CI to ensure the no-default-features works forever * update the README with the new example * fix the wasm client * adds a TODO * Update examples/cli-app-with-reqwest/src/main.rs * Update src/client.rs --------- Signed-off-by: shimatar0 <[email protected]> Co-authored-by: Tamo <[email protected]> Co-authored-by: Tamo <[email protected]>
1 parent 56ba49f commit 80f6326

File tree

25 files changed

+2268
-1436
lines changed

25 files changed

+2268
-1436
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ jobs:
3232
with:
3333
command: check
3434
args: --workspace --all-targets --all
35+
- name: Cargo check no default features
36+
uses: actions-rs/cargo@v1
37+
with:
38+
command: check
39+
args: --workspace --all-targets --all --no-default-features
3540

3641
linter:
3742
name: clippy-check

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ meilisearch-index-setting-macro = { path = "meilisearch-index-setting-macro", ve
2727
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
2828
futures = "0.3"
2929
futures-io = "0.3.26"
30-
isahc = { version = "1.0", features = ["http2", "text-decoding"], default_features = false }
30+
isahc = { version = "1.0", features = ["http2", "text-decoding"], optional = true, default_features = false }
3131
uuid = { version = "1.1.2", features = ["v4"] }
3232

3333
[target.'cfg(target_arch = "wasm32")'.dependencies]
@@ -37,8 +37,8 @@ wasm-bindgen = "0.2"
3737
wasm-bindgen-futures = "0.4"
3838

3939
[features]
40-
default = ["isahc-static-curl"]
41-
isahc-static-curl = ["isahc/static-curl"]
40+
default = ["isahc", "isahc", "isahc-static-curl"]
41+
isahc-static-curl = ["isahc", "isahc", "isahc/static-curl"]
4242
isahc-static-ssl = ["isahc/static-ssl"]
4343

4444
[dev-dependencies]

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ Json output:
238238
}
239239
```
240240

241+
#### Using users customized HttpClient <!-- omit in TOC -->
242+
243+
If you want to change the `HttpClient` you can incorporate using the `Client::new_with_client` method.
244+
To use it, you need to implement the `HttpClient Trait`(`isahc` is used by default).
245+
There are [using-reqwest-example](./examples/cli-app-with-reqwest) of using `reqwest`.
246+
241247
## 🌐 Running in the Browser with WASM <!-- omit in TOC -->
242248

243249
This crate fully supports WASM.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "cli-app-with-reqwest"
3+
version = "0.0.0"
4+
edition = "2021"
5+
publish = false
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
meilisearch-sdk = { path = "../..", default-features = false }
11+
futures = "0.3"
12+
serde = { version = "1.0", features = ["derive"] }
13+
serde_json = "1.0"
14+
lazy_static = "1.4.0"
15+
reqwest = "0.11.16"
16+
async-trait = "0.1.51"
17+
tokio = { version = "1.27.0", features = ["full"] }
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[
2+
{
3+
"id": 1,
4+
"seaon": "winter",
5+
"article": "sweater",
6+
"cost": 63.40,
7+
"size":"L",
8+
"pattern":"striped"
9+
},
10+
{
11+
"id": 2,
12+
"seaon": "spring",
13+
"article": "sweat pants",
14+
"cost": 18.00,
15+
"size":"XXXL",
16+
"pattern":"floral"
17+
},
18+
{
19+
"id": 3,
20+
"seaon": "fall",
21+
"article": "t-shirt",
22+
"cost": 1634.90,
23+
"size":"M",
24+
"pattern":"solid black"
25+
},
26+
{
27+
"id": 4,
28+
"seaon": "summer",
29+
"article": "tank top",
30+
"cost": 3.40,
31+
"size":"L",
32+
"pattern":"diagonal"
33+
},
34+
{
35+
"id": 5,
36+
"seaon": "winter",
37+
"article": "jeans",
38+
"cost": 4.20,
39+
"size":"XL",
40+
"pattern":"striped"
41+
},
42+
{
43+
"id": 6,
44+
"seaon": "spring",
45+
"article": "sun dress",
46+
"cost": 12634.56,
47+
"size":"L",
48+
"pattern":"floral"
49+
},
50+
{
51+
"id": 7,
52+
"seaon": "fall",
53+
"article": "sweatshirt",
54+
"cost": 90.80,
55+
"size":"M",
56+
"pattern":"checker"
57+
},
58+
{
59+
"id": 8,
60+
"seaon": "summer",
61+
"article": "shorts",
62+
"cost": 16.34,
63+
"size":"XS",
64+
"pattern":"solid beige"
65+
},
66+
{
67+
"id": 9,
68+
"seaon": "winter",
69+
"article": "jacket",
70+
"cost": 634,
71+
"size":"L",
72+
"pattern":"camo"
73+
}
74+
]

0 commit comments

Comments
 (0)