Skip to content

Conversation

Copy link

Copilot AI commented Nov 8, 2025

Replaced manual HttpClient calls with Refit, a type-safe REST client library.

Changes

Added Dependencies

  • Refit 7.2.22
  • Refit.HttpClientFactory 7.2.22

Implementation

  • Created resource-specific Refit interfaces for each WordPress REST API endpoint:

    • IPostsApi - Posts endpoint with CRUD operations
    • IPagesApi - Pages endpoint with CRUD operations
    • ICommentsApi - Comments endpoint with CRUD operations
    • ITagsApi - Tags taxonomy endpoint
    • ICategoriesApi - Categories taxonomy endpoint
    • IUsersApi - Users endpoint including current user
    • IMediaApi - Media/attachments endpoint
    • ITaxonomiesApi - Custom taxonomies endpoint
    • IPostTypesApi - Post types metadata endpoint
    • IPostStatusesApi - Post statuses endpoint
    • ISettingsApi - Site settings endpoint
    • IPluginsApi - Plugins management endpoint
    • IThemesApi - Themes management endpoint
    • IJWTAuthApi - JWT authentication endpoints
    • ICustomRequestApi - Generic/custom endpoint support with dynamic routing
    • All interfaces use Refit attributes (GET, POST, DELETE, HEAD) with authorization header support
  • Refactored HttpHelper to delegate all HTTP operations to Refit clients

    • Initializes all 15 resource-specific Refit clients in constructors using RestService.For<T>()
    • Added GetAuthHeader() to generate Bearer/Basic auth headers
    • Removed manual HttpRequestMessage construction and SetAuthHeader()
    • Uses CustomRequestApi for generic HTTP operations

Preserved Behavior

  • Public API unchanged - all client classes continue working without modification
  • Authentication (JWT Bearer, Basic), HttpResponsePreProcessing, and JsonSerializerSettings remain functional
  • Error handling and exception types unchanged

Example

Before:

using (HttpRequestMessage requestMessage = new(HttpMethod.Get, route))
{
    SetAuthHeader(isAuthRequired, requestMessage);
    response = await _httpClient.SendAsync(requestMessage).ConfigureAwait(false);
}

After:

string authHeader = isAuthRequired ? GetAuthHeader() : null;
response = await CustomRequestApi.GetAsync(route, authHeader).ConfigureAwait(false);
Original prompt

This section details on the original issue you should resolve

<issue_title>Use Refit for http calls </issue_title>
<issue_description>Use reactiveui refit internally for making the http calls.
</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: ThomasPe <4225039+ThomasPe@users.noreply.github.com>
Copilot AI changed the title [WIP] Use Refit for making HTTP calls Use Refit for HTTP calls Nov 8, 2025
Copilot AI requested a review from ThomasPe November 8, 2025 23:21
@ThomasPe
Copy link
Member

ThomasPe commented Nov 9, 2025

create an interface for each resource to be used with Refit @copilot

… endpoint

Co-authored-by: ThomasPe <4225039+ThomasPe@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 9, 2025

create an interface for each resource to be used with Refit @copilot

Created resource-specific Refit interfaces for each WordPress REST API endpoint:

  • IPostsApi, IPagesApi, ICommentsApi for content types
  • ITagsApi, ICategoriesApi, ITaxonomiesApi for taxonomies
  • IUsersApi, IMediaApi for core resources
  • IPostTypesApi, IPostStatusesApi for metadata
  • ISettingsApi, IPluginsApi, IThemesApi for site management
  • IJWTAuthApi for authentication
  • ICustomRequestApi for generic/custom endpoints

All interfaces include proper HTTP method attributes (GET, POST, DELETE, HEAD) and authorization header support. (commit 738dd2f)

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.

Use Refit for http calls

2 participants