Skip to content

examples: add context7 component in Rust#306

Merged
Mossaka merged 3 commits into
microsoft:mainfrom
Mossaka:mossaka/context7
Oct 9, 2025
Merged

examples: add context7 component in Rust#306
Mossaka merged 3 commits into
microsoft:mainfrom
Mossaka:mossaka/context7

Conversation

@Mossaka

@Mossaka Mossaka commented Sep 29, 2025

Copy link
Copy Markdown
Contributor

Signed-off-by: Jiaxiao Zhou duibao55328@gmail.com

@thomastaylor312 thomastaylor312 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great addition! Because this is an example, none of these are blocking

Comment thread examples/context7-rs/src/lib.rs Outdated
match make_request(Method::Get, &endpoint, None, get_api_key().as_deref()) {
Ok(body) => {
let body_trimmed = body.trim();
if body_trimmed.is_empty() || NO_CONTENT_MESSAGES.iter().any(|msg| body_trimmed == *msg) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: this could just be NO_CONTENT_MESSAGES.contains(body_trimmed)

.set_authority(Some(CONTEXT7_HOST))
.map_err(|_| "Failed to set authority".to_string())?;

let mut path = String::with_capacity(BASE_PATH.len() + endpoint.len() + 1);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: Document the magic number

Comment thread examples/context7-rs/src/lib.rs Outdated
Comment thread examples/context7-rs/src/lib.rs Outdated
Comment thread examples/context7-rs/src/lib.rs Outdated
}
}

fn make_request(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If you don't want to do all of this low level http code, consider importing https://docs.rs/wasmcloud-component/latest/wasmcloud_component/http/index.html. It has all the convenience wrappers around the http request stuff so you can just build requests and read responses using std::io::Read

Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
…xt7 implementation

Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
@Mossaka Mossaka merged commit 6c303f4 into microsoft:main Oct 9, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants