just keep the updated docs

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-02-04 14:45:06 +01:00
parent 36625b6d52
commit 198affd259
2 changed files with 16 additions and 16 deletions
@@ -84,7 +84,7 @@ The app port must proxy web socket connections in order to make hot reloading wo
## Alternatives to `global-agent`
The `proxy-agent` package can be used as an alternative to `global-agent` (do not install both!), and also ensures that the `node-fetch` library correctly respects proxy settings, but [does NOT work](https://github.com/TooTallNate/proxy-agents/issues/239) for modern `undici` based native Node.js `fetch`, so you'll have to also do the `undici` steps in the section above in addition to this.
The `proxy-agent` package can be used as an alternative to `global-agent` (do not install both!), and also ensures that the `node-fetch` library correctly respects proxy settings, but [does NOT work](https://github.com/TooTallNate/proxy-agents/issues/239) for modern `undici` based native Node.js `fetch`, so you'll still have to also do the `undici` steps in the section above in addition to this.
`proxy-agent` is a library that you can use to override the `globalAgents` of `node` land with a tunnel to use for each request.
@@ -2,7 +2,7 @@
id: adrs-adr013
title: 'ADR013: Proper use of HTTP fetching libraries'
# prettier-ignore
description: Architecture Decision Record (ADR) for the proper use of fetch libraries for data fetching.
description: Architecture Decision Record (ADR) for the proper use of fetchApiRef, node-fetch, and cross-fetch for data fetching.
---
## Context
@@ -12,13 +12,13 @@ support burden of keeping said package up to date.
## Decision
Newly written backend (Node.js) packages should use the native `fetch` call for HTTP data
fetching. Additionally, in legacy code, using the `node-fetch` library continues to be allowed. Other third party fetching libraries (for example `axios`, `got` etc) are not allowed. Example:
Backend (node) packages should use the `node-fetch` package for HTTP data
fetching. Example:
```ts
import fetch from 'node-fetch';
import { ResponseError } from '@backstage/errors';
// note that this is the global fetch, not imported from anywhere
const response = await fetch('https://example.com/api/v1/users.json');
if (!response.ok) {
throw await ResponseError.fromResponse(response);
@@ -26,19 +26,19 @@ if (!response.ok) {
const users = await response.json();
```
Frontend plugins and packages should use the [`fetchApiRef`](https://backstage.io/docs/reference/core-plugin-api.fetchapiref). Example:
Frontend plugins and packages should prefer to use the
[`fetchApiRef`](https://backstage.io/docs/reference/core-plugin-api.fetchapiref).
It uses `cross-fetch` internally. Example:
```ts
import { useApi, fetchApiRef } from '@backstage/core-plugin-api';
import { useApi } from '@backstage/core-plugin-api';
const { fetch } = useApi(fetchApiRef);
const MyComponent = () => {
const { fetch } = useApi(fetchApiRef);
const response = await fetch('https://example.com/api/v1/users.json');
if (!response.ok) {
throw await ResponseError.fromResponse(response);
}
const users = await response.json();
// ...
const response = await fetch('https://example.com/api/v1/users.json');
if (!response.ok) {
throw await ResponseError.fromResponse(response);
}
const users = await response.json();
```
Isomorphic packages should have a dependency on the `cross-fetch` package for
@@ -67,5 +67,5 @@ export class MyClient {
## Consequences
We will gradually transition away from third party packages such as `axios`,
`got` and others. Once we have transitioned to native `fetch` and `node-fetch` we will add lint
`got` and others. Once we have transitioned to `node-fetch` we will add lint
rules to enforce this decision.