Skip to content

Commit

Permalink
Feat trait to make clients customizable (#459)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Apr 10, 2024
1 parent 56ba49f commit 80f6326
Show file tree
Hide file tree
Showing 25 changed files with 2,268 additions and 1,436 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ jobs:
with:
command: check
args: --workspace --all-targets --all
- name: Cargo check no default features
uses: actions-rs/cargo@v1
with:
command: check
args: --workspace --all-targets --all --no-default-features

linter:
name: clippy-check
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ meilisearch-index-setting-macro = { path = "meilisearch-index-setting-macro", ve
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
futures = "0.3"
futures-io = "0.3.26"
isahc = { version = "1.0", features = ["http2", "text-decoding"], default_features = false }
isahc = { version = "1.0", features = ["http2", "text-decoding"], optional = true, default_features = false }
uuid = { version = "1.1.2", features = ["v4"] }

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

[features]
default = ["isahc-static-curl"]
isahc-static-curl = ["isahc/static-curl"]
default = ["isahc", "isahc", "isahc-static-curl"]
isahc-static-curl = ["isahc", "isahc", "isahc/static-curl"]
isahc-static-ssl = ["isahc/static-ssl"]

[dev-dependencies]
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ Json output:
}
```

#### Using users customized HttpClient <!-- omit in TOC -->

If you want to change the `HttpClient` you can incorporate using the `Client::new_with_client` method.
To use it, you need to implement the `HttpClient Trait`(`isahc` is used by default).
There are [using-reqwest-example](./examples/cli-app-with-reqwest) of using `reqwest`.

## 🌐 Running in the Browser with WASM <!-- omit in TOC -->

This crate fully supports WASM.
Expand Down
17 changes: 17 additions & 0 deletions examples/cli-app-with-reqwest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "cli-app-with-reqwest"
version = "0.0.0"
edition = "2021"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
meilisearch-sdk = { path = "../..", default-features = false }
futures = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
lazy_static = "1.4.0"
reqwest = "0.11.16"
async-trait = "0.1.51"
tokio = { version = "1.27.0", features = ["full"] }
74 changes: 74 additions & 0 deletions examples/cli-app-with-reqwest/assets/clothes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[
{
"id": 1,
"seaon": "winter",
"article": "sweater",
"cost": 63.40,
"size":"L",
"pattern":"striped"
},
{
"id": 2,
"seaon": "spring",
"article": "sweat pants",
"cost": 18.00,
"size":"XXXL",
"pattern":"floral"
},
{
"id": 3,
"seaon": "fall",
"article": "t-shirt",
"cost": 1634.90,
"size":"M",
"pattern":"solid black"
},
{
"id": 4,
"seaon": "summer",
"article": "tank top",
"cost": 3.40,
"size":"L",
"pattern":"diagonal"
},
{
"id": 5,
"seaon": "winter",
"article": "jeans",
"cost": 4.20,
"size":"XL",
"pattern":"striped"
},
{
"id": 6,
"seaon": "spring",
"article": "sun dress",
"cost": 12634.56,
"size":"L",
"pattern":"floral"
},
{
"id": 7,
"seaon": "fall",
"article": "sweatshirt",
"cost": 90.80,
"size":"M",
"pattern":"checker"
},
{
"id": 8,
"seaon": "summer",
"article": "shorts",
"cost": 16.34,
"size":"XS",
"pattern":"solid beige"
},
{
"id": 9,
"seaon": "winter",
"article": "jacket",
"cost": 634,
"size":"L",
"pattern":"camo"
}
]
Loading

0 comments on commit 80f6326

Please sign in to comment.