Skip to content

Commit a6375a4

Browse files
committed
max-length 100 prettier
1 parent c671247 commit a6375a4

File tree

105 files changed

+7668
-5770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+7668
-5770
lines changed

.github/ISSUE_TEMPLATE/1_Support_question.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ about: See https://api-platform.com/support/ for questions about using API Platf
55

66
# Support question
77

8-
We use GitHub issues only to discuss bugs and new features.
9-
For this kind of questions about using API Platform, please use
10-
any of the support alternatives shown in [API Platform support](https://api-platform.com/support/).
8+
We use GitHub issues only to discuss bugs and new features. For this kind of questions about using
9+
API Platform, please use any of the support alternatives shown in
10+
[API Platform support](https://api-platform.com/support/).
1111

1212
Thanks!

CONTRIBUTING.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
First of all, thank you for contributing, you're awesome!
44

5-
To have your code integrated in the API Platform documentation project, there are some rules to follow, but don't panic, it's easy!
5+
To have your code integrated in the API Platform documentation project, there are some rules to
6+
follow, but don't panic, it's easy!
67

78
## Reporting Bugs in the documentation
89

@@ -12,33 +13,36 @@ Before submitting your issue:
1213
- A clear title to resume the issue
1314
- A description of the workflow needed to reproduce the bug
1415

15-
> [!NOTE]
16-
> Don't hesitate giving as much information as you can.
16+
> [!NOTE] Don't hesitate giving as much information as you can.
1717
1818
## Code of Conduct
1919

20-
By contributing to this project, you agree to abide by our [Code of Conduct](https://github.com/api-platform/docs#coc-ov-file). We expect all contributors to foster a welcoming and inclusive environment.
20+
By contributing to this project, you agree to abide by our
21+
[Code of Conduct](https://github.com/api-platform/docs#coc-ov-file). We expect all contributors to
22+
foster a welcoming and inclusive environment.
2123

2224
## How to Contribute
2325

24-
1. Fork this repository by clicking the "Fork" button at the top right of the `api-platform/docs` repository page.
26+
1. Fork this repository by clicking the "Fork" button at the top right of the `api-platform/docs`
27+
repository page.
2528

2629
2. Clone the forked repository to your local machine:
2730

28-
```console
29-
git clone https://github.com/your-username/repository-name.git
30-
```
31+
```console
32+
git clone https://github.com/your-username/repository-name.git
33+
```
3134

3235
3. Create a new branch for your contribution:
3336

34-
```console
35-
git switch -c docs-your-branch-name
36-
```
37+
```console
38+
git switch -c docs-your-branch-name
39+
```
3740

3841
4. Commit and push your changes
39-
5. Submit a Pull Request. You must decide on what branch your changes will be based depending of the nature of the change.
40-
See [the dedicated documentation entry](https://api-platform.com/docs/extra/releases/).
42+
5. Submit a Pull Request. You must decide on what branch your changes will be based depending of the
43+
nature of the change. See
44+
[the dedicated documentation entry](https://api-platform.com/docs/extra/releases/).
4145

42-
> [!TIP]
43-
> You can also contribute to improving the documentation directly by clicking on the
44-
> **"You can also help us improve the documentation of this page."** link, located at the end of each documentation page.
46+
> [!TIP] You can also contribute to improving the documentation directly by clicking on the **"You
47+
> can also help us improve the documentation of this page."** link, located at the end of each
48+
> documentation page.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
[![Lint](https://github.com/api-platform/docs/actions/workflows/ci.yml/badge.svg)](https://github.com/api-platform/docs/actions/workflows/ci.yml)
66

7-
Welcome to the official documentation for [API Platform](https://api-platform.com), a powerful framework for building APIs and web applications.
7+
Welcome to the official documentation for [API Platform](https://api-platform.com), a powerful
8+
framework for building APIs and web applications.
89

910
This repository contains all the API Platform documentation resources.
1011

admin/advanced-customization.md

Lines changed: 228 additions & 138 deletions
Large diffs are not rendered by default.

admin/authentication-support.md

Lines changed: 84 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
API Platform Admin delegates the authentication support to React Admin.
44

5-
Refer to the [Auth Provider Setup](https://marmelab.com/react-admin/Authentication.html) documentation for more information.
5+
Refer to the [Auth Provider Setup](https://marmelab.com/react-admin/Authentication.html)
6+
documentation for more information.
67

7-
**Tip:** Once you have set up the authentication, you can also configure React Admin to perform client-side Authorization checks. Refer to the [Authorization](https://marmelab.com/react-admin/Permissions.html) documentation for more information.
8+
**Tip:** Once you have set up the authentication, you can also configure React Admin to perform
9+
client-side Authorization checks. Refer to the
10+
[Authorization](https://marmelab.com/react-admin/Permissions.html) documentation for more
11+
information.
812

913
## HydraAdmin
1014

11-
Enabling authentication support for [`<HydraAdmin>` component](./components.md#hydra) consists of a few parts, which need to be integrated together.
15+
Enabling authentication support for [`<HydraAdmin>` component](./components.md#hydra) consists of a
16+
few parts, which need to be integrated together.
1217

1318
In the following steps, we will see how to:
1419

@@ -18,52 +23,54 @@ In the following steps, we will see how to:
1823

1924
### Make Authenticated Requests
2025

21-
First, we need to implement a `getHeaders` function, that will add the Bearer token from `localStorage` (if there is one) to the `Authorization` header.
26+
First, we need to implement a `getHeaders` function, that will add the Bearer token from
27+
`localStorage` (if there is one) to the `Authorization` header.
2228

2329
```typescript
2430
const getHeaders = () =>
25-
localStorage.getItem("token")
26-
? { Authorization: `Bearer ${localStorage.getItem("token")}` }
27-
: {};
31+
localStorage.getItem("token")
32+
? { Authorization: `Bearer ${localStorage.getItem("token")}` }
33+
: {};
2834
```
2935

30-
Then, extend the Hydra `fetch` function to use the `getHeaders` function to add the `Authorization` header to the requests.
36+
Then, extend the Hydra `fetch` function to use the `getHeaders` function to add the `Authorization`
37+
header to the requests.
3138

3239
```typescript
33-
import {
34-
fetchHydra as baseFetchHydra,
35-
} from "@api-platform/admin";
40+
import { fetchHydra as baseFetchHydra } from "@api-platform/admin";
3641

3742
const fetchHydra = (url, options = {}) =>
38-
baseFetchHydra(url, {
39-
...options,
40-
headers: getHeaders,
41-
});
42-
43+
baseFetchHydra(url, {
44+
...options,
45+
headers: getHeaders,
46+
});
4347
```
4448

4549
### Redirect To Login Page
4650

47-
Then, we'll create a `<RedirectToLogin>` component, that will redirect users to the `/login` route if no token is available in the `localStorage`, and call the dataProvider's `introspect` function otherwise.
51+
Then, we'll create a `<RedirectToLogin>` component, that will redirect users to the `/login` route
52+
if no token is available in the `localStorage`, and call the dataProvider's `introspect` function
53+
otherwise.
4854

4955
```tsx
5056
import { Navigate } from "react-router-dom";
5157
import { useIntrospection } from "@api-platform/admin";
5258

5359
const RedirectToLogin = () => {
54-
const introspect = useIntrospection();
60+
const introspect = useIntrospection();
5561

56-
if (localStorage.getItem("token")) {
57-
introspect();
58-
return <></>;
59-
}
60-
return <Navigate to="/login" />;
62+
if (localStorage.getItem("token")) {
63+
introspect();
64+
return <></>;
65+
}
66+
return <Navigate to="/login" />;
6167
};
6268
```
6369

6470
### Clear Expired Tokens
6571

66-
Now, we will extend the `parseHydraDocumentaion` function (imported from the [@api-platform/api-doc-parser](https://github.com/api-platform/api-doc-parser) library).
72+
Now, we will extend the `parseHydraDocumentaion` function (imported from the
73+
[@api-platform/api-doc-parser](https://github.com/api-platform/api-doc-parser) library).
6774

6875
We will customize it to clear expired tokens when encountering unauthorized `401` response.
6976

@@ -72,39 +79,38 @@ import { parseHydraDocumentation } from "@api-platform/api-doc-parser";
7279
import { ENTRYPOINT } from "config/entrypoint";
7380

7481
const apiDocumentationParser = (setRedirectToLogin) => async () => {
75-
try {
76-
setRedirectToLogin(false);
77-
return await parseHydraDocumentation(ENTRYPOINT, { headers: getHeaders });
78-
} catch (result) {
79-
const { api, response, status } = result;
80-
if (status !== 401 || !response) {
81-
throw result;
82-
}
82+
try {
83+
setRedirectToLogin(false);
84+
return await parseHydraDocumentation(ENTRYPOINT, { headers: getHeaders });
85+
} catch (result) {
86+
const { api, response, status } = result;
87+
if (status !== 401 || !response) {
88+
throw result;
89+
}
8390

84-
localStorage.removeItem("token");
85-
setRedirectToLogin(true);
91+
localStorage.removeItem("token");
92+
setRedirectToLogin(true);
8693

87-
return { api, response, status };
88-
}
94+
return { api, response, status };
95+
}
8996
};
9097
```
9198

9299
### Extend The Data Provider
93100

94-
Now, we can initialize the Hydra data provider with the custom `fetchHydra` (with custom headers) and `apiDocumentationParser` functions created earlier.
101+
Now, we can initialize the Hydra data provider with the custom `fetchHydra` (with custom headers)
102+
and `apiDocumentationParser` functions created earlier.
95103

96104
```typescript
97-
import {
98-
hydraDataProvider as baseHydraDataProvider,
99-
} from "@api-platform/admin";
105+
import { hydraDataProvider as baseHydraDataProvider } from "@api-platform/admin";
100106
import { ENTRYPOINT } from "config/entrypoint";
101107

102108
const dataProvider = (setRedirectToLogin) =>
103-
baseHydraDataProvider({
104-
entrypoint: ENTRYPOINT,
105-
httpClient: fetchHydra,
106-
apiDocumentationParser: apiDocumentationParser(setRedirectToLogin),
107-
});
109+
baseHydraDataProvider({
110+
entrypoint: ENTRYPOINT,
111+
httpClient: fetchHydra,
112+
apiDocumentationParser: apiDocumentationParser(setRedirectToLogin),
113+
});
108114
```
109115

110116
### Update The Admin Component
@@ -168,22 +174,28 @@ export const Admin = () => {
168174

169175
### Example Implementation
170176

171-
For the implementation of the admin component, you can find a working example in the [API Platform's demo application](https://github.com/api-platform/demo/blob/4.0/pwa/components/admin/Admin.tsx).
177+
For the implementation of the admin component, you can find a working example in the
178+
[API Platform's demo application](https://github.com/api-platform/demo/blob/4.0/pwa/components/admin/Admin.tsx).
172179

173180
## OpenApiAdmin
174181

175-
This section explains how to set up and customize the [`<OpenApiAdmin>` component](./components.md/#openapi) to enable authentication.
182+
This section explains how to set up and customize the
183+
[`<OpenApiAdmin>` component](./components.md/#openapi) to enable authentication.
176184

177185
In the following steps, we will see how to:
178186

179187
- Make authenticated requests to the API (i.e. include the `Authorization` header)
180-
- Implement an authProvider to redirect users to the login page if they are not authenticated, and clear expired tokens when encountering unauthorized `401` response
188+
- Implement an authProvider to redirect users to the login page if they are not authenticated, and
189+
clear expired tokens when encountering unauthorized `401` response
181190

182191
### Making Authenticated Requests
183192

184-
First, we need to create a custom `httpClient` to add authentication tokens (via the the `Authorization` HTTP header) to requests.
193+
First, we need to create a custom `httpClient` to add authentication tokens (via the the
194+
`Authorization` HTTP header) to requests.
185195

186-
We will then configure `openApiDataProvider` to use [`ra-data-simple-rest`](https://github.com/marmelab/react-admin/blob/master/packages/ra-data-simple-rest/README.md), a simple REST dataProvider for React Admin, and make it use the `httpClient` we created earlier.
196+
We will then configure `openApiDataProvider` to use
197+
[`ra-data-simple-rest`](https://github.com/marmelab/react-admin/blob/master/packages/ra-data-simple-rest/README.md),
198+
a simple REST dataProvider for React Admin, and make it use the `httpClient` we created earlier.
187199

188200
```typescript
189201
// src/dataProvider.ts
@@ -193,7 +205,7 @@ const getAccessToken = () => localStorage.getItem("token");
193205
const httpClient = async (url: string, options: fetchUtils.Options = {}) => {
194206
options.headers = new Headers({
195207
...options.headers,
196-
Accept: 'application/json',
208+
Accept: "application/json",
197209
}) as Headers;
198210

199211
const token = getAccessToken();
@@ -203,19 +215,23 @@ const httpClient = async (url: string, options: fetchUtils.Options = {}) => {
203215
};
204216

205217
const dataProvider = openApiDataProvider({
206-
dataProvider: simpleRestProvider(API_ENTRYPOINT_PATH, httpClient),
207-
entrypoint: API_ENTRYPOINT_PATH,
208-
docEntrypoint: API_DOCS_PATH,
218+
dataProvider: simpleRestProvider(API_ENTRYPOINT_PATH, httpClient),
219+
entrypoint: API_ENTRYPOINT_PATH,
220+
docEntrypoint: API_DOCS_PATH,
209221
});
210222
```
211223

212-
**Note:** The `simpleRestProvider` provider expect the API to include a `Content-Range` header in the response. You can find more about the header syntax in the [Mozilla’s MDN documentation: Content-Range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range).
224+
**Note:** The `simpleRestProvider` provider expect the API to include a `Content-Range` header in
225+
the response. You can find more about the header syntax in the
226+
[Mozilla’s MDN documentation: Content-Range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range).
213227

214-
**Note:** The `getAccessToken` function retrieves the JWT token stored in the browser's localStorage. Replace it with your own logic in case you don't store the token that way.
228+
**Note:** The `getAccessToken` function retrieves the JWT token stored in the browser's
229+
localStorage. Replace it with your own logic in case you don't store the token that way.
215230

216231
### Creating The AuthProvider
217232

218-
Now let's create and export an `authProvider` object that handles authentication and authorization logic.
233+
Now let's create and export an `authProvider` object that handles authentication and authorization
234+
logic.
219235

220236
```typescript
221237
// src/authProvider.ts
@@ -228,7 +244,7 @@ interface JwtPayload {
228244
const getAccessToken = () => localStorage.getItem("token");
229245

230246
const authProvider = {
231-
login: async ({username, password}: { username: string; password: string }) => {
247+
login: async ({ username, password }: { username: string; password: string }) => {
232248
const request = new Request(API_AUTH_PATH, {
233249
method: "POST",
234250
body: JSON.stringify({ email: username, password }),
@@ -248,7 +264,7 @@ const authProvider = {
248264
localStorage.removeItem("token");
249265
return Promise.resolve();
250266
},
251-
checkAuth: () => getAccessToken() ? Promise.resolve() : Promise.reject(),
267+
checkAuth: () => (getAccessToken() ? Promise.resolve() : Promise.reject()),
252268
checkError: (error: { status: number }) => {
253269
const status = error.status;
254270
if (status === 401 || status === 403) {
@@ -279,22 +295,23 @@ export default authProvider;
279295

280296
### Updating The Admin Component
281297

282-
Finally, we can update the `Admin` component to use the `authProvider` and `dataProvider` we created earlier.
298+
Finally, we can update the `Admin` component to use the `authProvider` and `dataProvider` we created
299+
earlier.
283300

284301
```tsx
285302
// src/Admin.tsx
286303

287-
import { OpenApiAdmin } from '@api-platform/admin';
304+
import { OpenApiAdmin } from "@api-platform/admin";
288305
import authProvider from "./authProvider";
289306
import dataProvider from "./dataProvider";
290307
import { API_DOCS_PATH, API_ENTRYPOINT_PATH } from "./config/api";
291308

292309
export default () => (
293-
<OpenApiAdmin
294-
entrypoint={API_ENTRYPOINT_PATH}
295-
docEntrypoint={API_DOCS_PATH}
296-
dataProvider={dataProvider}
297-
authProvider={authProvider}
298-
/>
310+
<OpenApiAdmin
311+
entrypoint={API_ENTRYPOINT_PATH}
312+
docEntrypoint={API_DOCS_PATH}
313+
dataProvider={dataProvider}
314+
authProvider={authProvider}
315+
/>
299316
);
300317
```

0 commit comments

Comments
 (0)