Skip to content

Commit c873a42

Browse files
committed
docs: revamp the getting started section
1 parent 505e82f commit c873a42

File tree

3 files changed

+76
-16
lines changed

3 files changed

+76
-16
lines changed

admin/getting-started.md

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,99 @@
11
# Getting Started
22

3-
## Installation
3+
## API Platform Symfony variant
44

5-
If you use the [API Platform Symfony variant](../symfony/), API Platform Admin is already installed, you can skip this installation guide.
5+
If you use the [API Platform Symfony variant](../symfony/), good news, API Platform Admin is already installed! 🎉
66

7-
Otherwise, follow this guide.
7+
You can access it by visiting `/admin` on your API Platform application.
88

9-
If you don't have an existing React Application, create one using [Create React App](https://create-react-app.dev/):
9+
When running locally, you can also click on the "Admin" button of the welcome page at https://localhost.
1010

11-
```console
12-
npm init react-app my-admin
11+
![API Platform welcome page](./images/api-platform-welcome-page.png)
12+
13+
Here is what it looks like with a simple API exposing a `Greetings` resource:
14+
15+
![Basic admin with the Greetings resource](./images/basic-admin-greetings.png)
16+
17+
## Manual Installation
18+
19+
If you did not use the Symfony variant of API Platform and need to install API Platform Admin manually, follow this guide.
20+
21+
First, let's scaffold a React Admin Application by using the [Create React Admin](https://marmelab.com/react-admin/CreateReactAdmin.html) tool:
22+
23+
```bash
24+
npx create-react-admin@latest my-admin
1325
cd my-admin
1426
```
1527

1628
Then, install the `@api-platform/admin` library:
1729

18-
```console
30+
```bash
1931
npm install @api-platform/admin
2032
```
2133

22-
## Creating the Admin
34+
Now you can use either:
2335

24-
To initialize API Platform Admin, register it in your application.
25-
For instance, if you used Create React App, replace the content of `src/App.js` by:
36+
- [`<HydraAdmin>`](#using-hydraadmin) to connect your app to an API exposing a Hydra documentation
37+
- [`<OpenApiAdmin>`](#using-openapiadmin) to connect your app to an API exposing an OpenAPI documentation
2638

27-
```javascript
28-
import { HydraAdmin } from '@api-platform/admin';
39+
## Using `HydraAdmin`
40+
41+
You can use the [`<HydraAdmin>`](./components.md#hydraadmin) component exported by `@api-platform/admin` to connect your app to an API exposing a Hydra documentation.
42+
43+
If you used Create React Admin, you can replace the content of `src/App.tsx` by:
44+
45+
```tsx
46+
import { HydraAdmin } from "@api-platform/admin";
2947

3048
// Replace with your own API entrypoint
3149
// For instance if https://example.com/api/books is the path to the collection of book resources, then the entrypoint is https://example.com/api
32-
export default () => <HydraAdmin entrypoint="https://demo.api-platform.com" />;
50+
export const App = () => <HydraAdmin entrypoint="https://localhost" />;
51+
```
52+
53+
**Tip:** if you don't want to hardcode the API URL, you can [use an environment variable](https://vite.dev/guide/env-and-mode).
54+
55+
Your new administration interface is ready! `HydraAdmin` will automatically fetch the Hydra documentation of your API and generate CRUD pages for all the resources it exposes.
56+
57+
Type `npm run dev` to try it!
58+
59+
![Basic admin with the Greetings resource](./images/basic-admin-greetings.png)
60+
61+
**Tip:** There are more props you can pass to the `HydraAdmin` component to customize the dataProvider or the connection to Mercure. Check the [API documentation](./components.md#hydraadmin) for more information.
62+
63+
**Tip:** You may also need to configure your API to set the correct CORS headers. Refer to the [Configuring CORS](#configuring-cors) section below to learn more.
64+
65+
## Using `OpenApiAdmin`
66+
67+
You can use the [`<OpenApiAdmin>`](./components.md#openapiadmin) component exported by `@api-platform/admin` to connect your app to an API exposing an OpenAPI documentation.
68+
69+
If you used Create React Admin, you can replace the content of `src/App.tsx` by:
70+
71+
```tsx
72+
import { OpenApiAdmin } from "@api-platform/admin";
73+
74+
// Replace with your own API entrypoint
75+
export const App = () => (
76+
<OpenApiAdmin
77+
entrypoint="https://localhost"
78+
docEntrypoint="https://localhost/docs.jsonopenapi"
79+
/>
80+
);
3381
```
3482

83+
**Tip:** if you don't want to hardcode the API URL, you can [use an environment variable](https://vite.dev/guide/env-and-mode).
84+
85+
Your new administration interface is ready! `OpenApiAdmin` will automatically fetch the Hydra documentation of your API and generate CRUD pages for all the resources it exposes.
86+
87+
Type `npm run dev` to try it!
88+
89+
![Basic admin with the Greetings resource](./images/basic-admin-greetings.png)
90+
91+
**Tip:** There are more props you can pass to the `OpenApiAdmin` component to customize the dataProvider or the connection to Mercure. Check the [API documentation](./components.md#openapiadmin) for more information.
92+
93+
**Tip:** You may also need to configure your API to set the correct CORS headers. Refer to the [Configuring CORS](#configuring-cors) section below to learn more.
94+
95+
## Configuring CORS
96+
3597
Be sure to make your API send proper [CORS HTTP headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) to allow
3698
the admin's domain to access it.
3799

@@ -61,6 +123,4 @@ Clear the cache to apply this change:
61123
bin/console cache:clear --env=prod
62124
```
63125

64-
Your new administration interface is ready! Type `npm start` to try it!
65-
66-
Note: if you don't want to hardcode the API URL, you can [use an environment variable](https://create-react-app.dev/docs/adding-custom-environment-variables).
126+
**Next step:** Learn how to add more features to your generated Admin by [Customizing the Schema](./schema-org.md).
154 KB
Loading
32.2 KB
Loading

0 commit comments

Comments
 (0)