Skip to content

Conversation

@kumarUjjawal
Copy link
Contributor

@kumarUjjawal kumarUjjawal commented Oct 18, 2025

Pull Request

Related issue

Fixes #697

What does this PR do?

Created a new module to support the webhook API.

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Summary by CodeRabbit

  • New Features

    • Full webhook management in the client: create, list, get, update, and delete webhooks
    • Fine-grained header controls with partial-update semantics: add, remove, and reset headers
  • Documentation

    • Added usage examples and code samples demonstrating webhook CRUD and header update flows
  • Tests

    • Added serialization and end-to-end webhook CRUD tests

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 18, 2025

Walkthrough

Adds full webhook API support: new webhooks module with request/response models and custom serialization, five new async Client methods for webhook CRUD, uuid gains the serde feature, code-samples for webhooks, and tests exercising webhook create/read/update/delete flows.

Changes

Cohort / File(s) Summary
Code samples
.code-samples.meilisearch.yaml
Adds webhook usage examples: get_webhooks, get_webhook, create_webhook, update_webhook, delete_webhook.
Dependencies
Cargo.toml
Enables serde feature for uuid in [dependencies] and in [target.'cfg(target_arch = "wasm32")'.dependencies] (added "serde" alongside existing features).
Client API
src/lib.rs, src/client.rs
Exposes pub mod webhooks and adds five async Client methods: get_webhooks, get_webhook, create_webhook, update_webhook, delete_webhook, using webhook types from crate::webhooks.
Webhook implementation & tests
src/webhooks.rs
Adds webhook models and APIs: Webhook, WebhookInfo, WebhookList, WebhookCreate (builders), WebhookUpdate (fluent API with internal HeadersUpdate state machine), custom Serialize for partial updates (including header set/remove/reset semantics), and unit/integration tests covering serialization and CRUD flows.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant User
    participant Client
    participant HttpClient
    participant MeilisearchAPI

    rect rgb(235,248,255)
    Note over User,Client: Create webhook
    User->>Client: create_webhook(WebhookCreate)
    Client->>Client: serialize WebhookCreate
    Client->>HttpClient: POST /webhooks
    HttpClient->>MeilisearchAPI: POST /webhooks
    MeilisearchAPI-->>HttpClient: 201 WebhookInfo
    HttpClient-->>Client: WebhookInfo
    Client-->>User: WebhookInfo
    end

    rect rgb(245,255,235)
    Note over User,Client: List webhooks
    User->>Client: get_webhooks()
    Client->>HttpClient: GET /webhooks
    HttpClient->>MeilisearchAPI: GET /webhooks
    MeilisearchAPI-->>HttpClient: 200 WebhookList
    HttpClient-->>Client: WebhookList
    Client-->>User: WebhookList
    end

    rect rgb(255,245,235)
    Note over User,Client: Update webhook (partial)
    User->>Client: update_webhook(uuid, WebhookUpdate)
    Client->>Client: serialize WebhookUpdate (HeadersUpdate state)
    Client->>HttpClient: PATCH /webhooks/{uuid}
    HttpClient->>MeilisearchAPI: PATCH /webhooks/{uuid}
    MeilisearchAPI-->>HttpClient: 200 WebhookInfo
    HttpClient-->>Client: WebhookInfo
    Client-->>User: WebhookInfo
    end

    rect rgb(250,250,250)
    Note over User,Client: Delete webhook
    User->>Client: delete_webhook(uuid)
    Client->>HttpClient: DELETE /webhooks/{uuid}
    HttpClient->>MeilisearchAPI: DELETE /webhooks/{uuid}
    MeilisearchAPI-->>HttpClient: 204 No Content
    HttpClient-->>Client: ()
    Client-->>User: ()
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐇
I hopped through code to stitch a bell,
Webhooks listening — headers, url and spell.
Create, read, patch, remove with care,
UUIDs now whisper serde-air.
Hop on — the callbacks dance and dwell.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues Check ✅ Passed The pull request addresses all three primary objectives from issue #697: SDK methods for webhook CRUD operations are implemented in src/client.rs with five public methods (get_webhooks, get_webhook, create_webhook, update_webhook, delete_webhook) [#697]; comprehensive test cases are included in src/webhooks.rs covering serialization variants and integration workflows [#697]; and code samples for all five required keys (webhooks_get_1, webhooks_get_single_1, webhooks_post_1, webhooks_patch_1, webhooks_delete_1) are added to .code-samples.meilisearch.yaml [#697]. The webhook module also includes complete data models with appropriate serialization logic to support these operations.
Out of Scope Changes Check ✅ Passed All changes in the pull request are directly related to webhook API support and fall within the scope of issue #697. The modifications include the new webhooks module with data models and tests, client methods for webhook operations, code samples demonstrating webhook usage, and a dependency update to the uuid crate adding the serde feature—which is necessary for serializing webhook types that contain UUID fields. No unrelated refactoring, unrelated bug fixes, or tangential improvements are present in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 91.67% which is sufficient. The required threshold is 80.00%.
Title Check ✅ Passed The PR title "Add support for webhook API" is fully aligned with the changeset. The entire pull request is dedicated to implementing webhook API support across multiple files: a new webhooks module with complete data models and builder APIs in src/webhooks.rs, new client methods for webhook CRUD operations in src/client.rs, code samples in .code-samples.meilisearch.yaml, and necessary dependency updates in Cargo.toml. The title is concise, specific, and clearly describes the primary objective without vague language or misleading details.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
src/webhooks.rs (4)

33-41: Create payload API is clear; small naming nit

Both with_header(self) and insert_header(&mut self) are handy. Consider aligning names (e.g., with_header/with_header_mut) for symmetry, but optional.

Also applies to: 43-68


83-137: Update builder is practical; optional ergonomic variant

Current &mut builder works. Optionally add a by‑value variant for chaining from new(), mirroring WebhookCreate.

 impl WebhookUpdate {
-    pub fn new() -> Self { Self::default() }
+    pub fn new() -> Self { Self::default() }
+    #[must_use]
+    pub fn with_url_owned(mut self, url: impl Into<String>) -> Self {
+        self.url = Some(url.into());
+        self
+    }
 }

139-167: Avoid serde_json dependency in Serialize impl (minor)

You can emit null without importing serde_json by serializing an Option::None.

-            HeadersUpdate::Reset => {
-                map.serialize_entry("headers", &Value::Null)?;
-            }
+            HeadersUpdate::Reset => {
+                let none: Option<()> = None;
+                map.serialize_entry("headers", &none)?;
+            }

199-241: Consider adding reset_headers() call to webhook_crud integration test for comprehensive e2e coverage

The reset_headers() method exists (line 133, src/webhooks.rs) and correctly serializes to "headers": null, which per Meilisearch 1.17 API clears all headers server-side. While your current test validates set/remove operations, adding a step that calls reset_headers() and asserts headers are cleared would provide complete end-to-end coverage—especially since a unit test already validates the serialization (lines 193–196).

.code-samples.meilisearch.yaml (1)

1959-1977: Samples look good; fully qualify types to avoid missing imports

If the docs runner doesn’t inject imports, qualify WebhookCreate/WebhookUpdate.

-  let mut payload = WebhookCreate::new("WEBHOOK_TARGET_URL");
+  let mut payload = meilisearch_sdk::webhooks::WebhookCreate::new("WEBHOOK_TARGET_URL");
@@
-  let mut update = WebhookUpdate::new();
+  let mut update = meilisearch_sdk::webhooks::WebhookUpdate::new();

Please run the docs build to ensure these snippets compile where expected.

src/client.rs (1)

1221-1250: get_webhook by UUID: consider a Uuid overload

Current signature is fine. Optionally add a helper accepting &Uuid to avoid callers allocating strings.

pub async fn get_webhook_uuid(&self, id: &uuid::Uuid) -> Result<WebhookInfo, Error> {
    self.get_webhook(id.to_string()).await
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e84bdf and db9f85e.

📒 Files selected for processing (5)
  • .code-samples.meilisearch.yaml (1 hunks)
  • Cargo.toml (2 hunks)
  • src/client.rs (2 hunks)
  • src/lib.rs (1 hunks)
  • src/webhooks.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/webhooks.rs (2)
src/client.rs (3)
  • new (54-66)
  • None (1446-1446)
  • None (1525-1525)
meilisearch-test-macro/src/lib.rs (1)
  • meilisearch_test (14-201)
🔇 Additional comments (12)
Cargo.toml (1)

29-29: uuid + serde enablement looks correct

Matches the new webhook models’ need to (de)serialize Uuid; wasm config keeps default-features off while enabling "js" + "serde". LGTM.

Also applies to: 40-40

src/webhooks.rs (5)

7-14: Webhook model: solid and idiomatic

Correct fields, defaults, and casing; ready for round‑trip with API.


16-24: Flattened WebhookInfo is appropriate

Flatten avoids nested payloads and matches typical Meilisearch responses.


26-31: List wrapper matches GET /webhooks

Simple and sufficient.


70-81: HeadersUpdate states are well chosen

NotSet/Reset/Set cleanly encode API semantics.


176-197: Serialize tests cover set/remove/reset cases

Good coverage for JSON shape.

src/lib.rs (1)

267-268: Module export is in the right place

Publicly exposing webhooks alongside other top‑level modules is correct.

src/client.rs (5)

17-17: Importing webhook types: OK

Types are correctly surfaced from the new module.


1193-1220: get_webhooks aligns with conventions

Endpoint, method, and 200 status match expectations.


1252-1285: create_webhook: good status and typing

201 on POST and typed body are consistent with the rest of the client.


1287-1325: update_webhook: PATCH 200 looks right

Uses custom-serializing WebhookUpdate; matches SDK patterns.

If Meilisearch returns 202 for async updates in some configurations, confirm 200 is always correct for this endpoint.


1327-1353: delete_webhook: 204 No Content is correct

Clean and consistent with other delete methods.

@codecov
Copy link

codecov bot commented Oct 18, 2025

Codecov Report

❌ Patch coverage is 93.47826% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.18%. Comparing base (5e84bdf) to head (e8b06f7).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/webhooks.rs 90.69% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #719      +/-   ##
==========================================
+ Coverage   85.90%   86.18%   +0.28%     
==========================================
  Files          19       20       +1     
  Lines        6079     6263     +184     
==========================================
+ Hits         5222     5398     +176     
- Misses        857      865       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/webhooks.rs (1)

205-253: LGTM! Comprehensive CRUD integration test.

The test thoroughly exercises the webhook lifecycle:

  • Creates webhook with headers
  • Fetches and verifies creation
  • Updates headers (remove + add)
  • Resets all headers
  • Deletes and verifies removal

The test properly handles potential race conditions when verifying deletion (lines 247-250).

Consider adding test coverage for edge cases:

  • Creating webhook without headers
  • Updating URL without touching headers
  • Error handling (e.g., invalid UUID, non-existent webhook)

These would strengthen confidence in error paths and optional field handling.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db9f85e and 653c367.

📒 Files selected for processing (2)
  • .code-samples.meilisearch.yaml (1 hunks)
  • src/webhooks.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/webhooks.rs (2)
src/client.rs (3)
  • new (54-66)
  • None (1446-1446)
  • None (1525-1525)
meilisearch-test-macro/src/lib.rs (1)
  • meilisearch_test (14-201)
🔇 Additional comments (3)
.code-samples.meilisearch.yaml (1)

1959-1977: LGTM! Webhook code samples look correct.

All five webhook samples align well with the new API surface and demonstrate the expected CRUD operations. The samples correctly show:

  • Retrieving all webhooks and a single webhook by UUID
  • Creating a webhook with custom headers
  • Updating a webhook to remove headers
  • Deleting a webhook
src/webhooks.rs (2)

144-173: LGTM! Custom serialization correctly implements PATCH semantics.

The custom Serialize implementation properly handles partial update semantics:

  • Only serializes fields that were explicitly set
  • Distinguishes between omitted fields (NotSet) and explicit reset (null)
  • Correctly serializes header modifications (add/update vs. remove)

This design pattern effectively supports RESTful PATCH operations.


182-203: LGTM! Serialization test correctly validates PATCH semantics.

The test effectively verifies:

  • Header set/remove operations serialize to the correct JSON structure
  • Reset operation serializes headers field to null
  • Only modified fields are included in the output

@curquiza curquiza changed the title feat: Add support for webhook API Add support for webhook API Oct 22, 2025
@curquiza curquiza added the enhancement New feature or request label Oct 22, 2025
Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors merge

@meili-bors
Copy link
Contributor

meili-bors bot commented Oct 22, 2025

@meili-bors meili-bors bot merged commit 601a066 into meilisearch:main Oct 22, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v1.17.0] Add support for webhook API

2 participants