Skip to main content

HttpClient

Trait HttpClient 

Source
pub trait HttpClient: Send + Sync {
    // Required methods
    fn get_bytes(&self, url: &str) -> Result<Vec<u8>, SkillfileError>;
    fn get_json(&self, url: &str) -> Result<Option<String>, SkillfileError>;
    fn post_json(
        &self,
        url: &str,
        body: &str,
    ) -> Result<Vec<u8>, SkillfileError>;

    // Provided method
    fn post_json_with_bearer(
        &self,
        req: &BearerPost<'_>,
    ) -> Result<Vec<u8>, SkillfileError> { ... }
}
Expand description

Contract for HTTP GET requests used by the fetcher/resolver layer.

Implementations are responsible for:

  • Setting standard headers (User-Agent, Authorization)
  • Connection pooling / agent reuse
  • Error mapping to SkillfileError

The trait has three methods covering the HTTP patterns in this codebase:

  • get_bytes: raw file downloads (content from raw.githubusercontent.com)
  • get_json: GitHub API calls that may return 4xx gracefully
  • post_json: POST with JSON body (used by some registry APIs)

Required Methods§

Source

fn get_bytes(&self, url: &str) -> Result<Vec<u8>, SkillfileError>

Returns Err(SkillfileError::Network) on HTTP errors (including 404).

Source

fn get_json(&self, url: &str) -> Result<Option<String>, SkillfileError>

GET a URL with Accept: application/vnd.github.v3+json header.

Returns Ok(None) on 4xx client errors (used for tentative lookups like SHA resolution where a missing ref is not fatal). Returns Err on network/server errors.

Source

fn post_json(&self, url: &str, body: &str) -> Result<Vec<u8>, SkillfileError>

POST a JSON body to a URL and return the response body as bytes.

Returns Err(SkillfileError::Network) on HTTP or network errors.

Provided Methods§

Source

fn post_json_with_bearer( &self, req: &BearerPost<'_>, ) -> Result<Vec<u8>, SkillfileError>

POST with a custom Authorization: Bearer header (for non-GitHub APIs).

Default: ignores the token and delegates to post_json. Test mocks use this default; UreqClient overrides to send the header.

§Note

The extra token parameter is required by non-GitHub registry APIs (e.g. skillhub.club).

Implementors§