Skip to content

Comments

V16: Replace legacy/fetch with @hey-api/client-fetch#19002

Merged
iOvergaard merged 65 commits intov16/devfrom
v16/feature/client-fetch
Apr 14, 2025
Merged

V16: Replace legacy/fetch with @hey-api/client-fetch#19002
iOvergaard merged 65 commits intov16/devfrom
v16/feature/client-fetch

Conversation

@iOvergaard
Copy link
Contributor

@iOvergaard iOvergaard commented Apr 10, 2025

Description

This pull request includes several changes to the Umbraco.Web.UI.Client project, focusing on refactoring the backend API integration and updating dependencies. The most important changes include modifying the package.json and package-lock.json files, updating the API client configuration, and replacing the HTTP client with @hey-api/client-fetch.

The reason for the many file changes is that the profile of the generated SDKs have changed moving from legacy/fetch to @hey-api/client-fetch in that we now have to supply each part of a call in their respective parts, i.e. body, path, and query are now separate objects.

Breaking Changes

HTTP Client

The global object OpenAPI imported from @umbraco-cms/backoffice/external/backend-api is replaced with a new HTTP client, which is used like this:

import { umbHttpClient } from '@umbraco-cms/backoffice/http-client';

The client is generated using @hey-api/client-fetch and can be used as a stand-in for other generated @hey-api SDKs, meaning you can use it when connecting to your controllers. The client comes equipped with authentication and error handling, and will eventually support retrying requests after successful login.

Another great feature is that the client can be used directly to make HTTP requests without having an SDK (generated factory functions):

// GET
const response = await umbHttpClient.get({ url: '/umbraco/my-api-controller' })

// POST
umbHttpClient.post({ url: '/umbraco/my-api-controller', body: { property: value } })

Note

Read more about @hey-api/fetch-client on their website

tryExecuteAndNotify

The utility tryExecuteAndNotify has been deprecated in favor of using the base tryExecute function, which now supports showing error notifications. See #18939 for more details.

tryExecute

  • The lesser-known utility function tryExecute now requires the first argument to be a controller host. See V16: Updates openapi-ts client and deprecates tryExecuteAndNotify #18939 for more details.
  • The return type is now the UmbApiResponse<T = unknown> = T & UmbApiErrorResponse type, which in essence means that the data property is not guaranteed. Instead, it will return exactly the promise return type that was given to it with an added error property. In cases where a @hey-api SDK was used, you will get the data in a data property anyway. This is done to ensure that tryExecute does not return a nested data.data object and gives a cleaner model.
  • There is now no longer a dependency on the repository module where the old type known as UmbDataSourceResponse lives. Instead, this type is now exclusively used for data sources.

Tree repositories

To comply with the usage of UmbDataSourceResponse, some base interfaces for tree repositories now require this model. This makes it easier to map directly from an API model into a data source.

Other changes

Dependency Updates and Configuration Changes:

API Client Refactoring:

…pport @hey-api/client-fetch) or the given type if the response does not contain a 'data' object
Copilot AI review requested due to automatic review settings April 10, 2025 12:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 223 out of 225 changed files in this pull request and generated no comments.

Files not reviewed (2)
  • src/Umbraco.Web.UI.Client/package-lock.json: Language not supported
  • src/Umbraco.Web.UI.Client/package.json: Language not supported

@iOvergaard iOvergaard requested review from leekelleher and removed request for leekelleher April 10, 2025 12:53
@iOvergaard iOvergaard requested a review from leekelleher April 10, 2025 14:47
@iOvergaard iOvergaard added the preview/backoffice Pull requests that can be previewed in a static version of the Backoffice label Apr 10, 2025
@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://victorious-ground-017b08103-19002.westeurope.6.azurestaticapps.net

Copy link
Member

@leekelleher leekelleher left a comment

Choose a reason for hiding this comment

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

Tested out, working as expected. I'm happy with the code changes. 🚀

@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://victorious-ground-017b08103-19002.westeurope.6.azurestaticapps.net

@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://victorious-ground-017b08103-19002.westeurope.6.azurestaticapps.net

@iOvergaard iOvergaard merged commit 3939742 into v16/dev Apr 14, 2025
10 of 14 checks passed
@iOvergaard iOvergaard deleted the v16/feature/client-fetch branch April 14, 2025 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/frontend category/breaking category/notable dependencies Pull requests that update a dependency file preview/backoffice Pull requests that can be previewed in a static version of the Backoffice type/feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants