Skip to content

Commit 42b7353

Browse files
authored
docs: update client generator (#1601)
1 parent 5a2f9fc commit 42b7353

File tree

10 files changed

+145
-170
lines changed

10 files changed

+145
-170
lines changed

client-generator/index.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
11
# The API Platform Client Generator
22

3-
Client Generator is the fastest way to scaffold fully featured webapps and native mobile apps from APIs supporting the [Hydra](http://www.hydra-cg.com/) format.
3+
Client Generator is the fastest way to scaffold fully featured webapps
4+
and native mobile apps from APIs supporting the [Hydra](http://www.hydra-cg.com/) or [OpenAPI](https://www.openapis.org/) format.
45

56
![Screencast](images/client-generator-demo.gif)
67

78
## Generated React and React Native Apps, Updated in Real Time
89

910
It is able to generate apps using the following frontend stacks:
1011

11-
- [Next.js](nextjs.md)
12-
- [Nuxt.js](nuxtjs.md)
13-
- [Quasar Framework](quasar.md)
14-
- [Vuetify](vuetify.md)
15-
- [React with Redux](react.md)
16-
- [React Native](react-native.md)
17-
- [Vue.js](vuejs.md)
18-
- [Or bring your custom generator](custom.md)
12+
- [React](react.md)
13+
- [Next.js](nextjs.md)
14+
- [React Native](react-native.md)
15+
- [Vue.js](vuejs.md)
16+
- [Nuxt.js](nuxtjs.md)
17+
- [Quasar Framework](quasar.md)
18+
- [Vuetify](vuetify.md)
19+
- [Or bring your custom generator](custom.md)
1920

2021
Client Generator works especially well with APIs built with the [API Platform](https://api-platform.com) framework.
2122

2223
## Features
2324

24-
- Generates high-quality ES6:
25-
- list view (with pagination)
26-
- detail view
27-
- creation form
28-
- update form
29-
- delete button
30-
- Supports to-one and to-many relations
31-
- Uses the appropriate input type (`number`, `date`...)
32-
- Client-side validation
33-
- Subscribes to data updates pushed by servers supporting [the Mercure protocol](https://mercure.rocks)
34-
- Displays server-side validation errors under the related input (if using API Platform Core)
35-
- Integration with [Bootstrap](https://getbootstrap.com/) and [FontAwesome](https://fontawesome.com/) (Progressive Web Apps)
36-
- Integration with [React Native Elements](https://react-native-training.github.io/react-native-elements/)
37-
- Accessible to people with disabilities ([ARIA](https://www.w3.org/WAI/intro/aria) support in webapps)
25+
- Generates high-quality ES6:
26+
- list view (with pagination)
27+
- detail view
28+
- creation form
29+
- update form
30+
- delete button
31+
- Supports to-one and to-many relations
32+
- Uses the appropriate input type (`number`, `date`...)
33+
- Client-side validation
34+
- Subscribes to data updates pushed by servers supporting [the Mercure protocol](https://mercure.rocks)
35+
- Displays server-side validation errors under the related input (if using API Platform Core)
36+
- Integration with [Bootstrap](https://getbootstrap.com/) and [FontAwesome](https://fontawesome.com/) (Progressive Web Apps)
37+
- Integration with [React Native Elements](https://react-native-training.github.io/react-native-elements/)
38+
- Accessible to people with disabilities ([ARIA](https://www.w3.org/WAI/intro/aria) support in webapps)

client-generator/nextjs.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,59 @@
22

33
![List screenshot](images/nextjs/client-generator-nextjs-list.png)
44

5-
The Next.js Client Generator generates components for Server Side Rendered applications using [Next.js](https://zeit.co/blog/next)
5+
The Next.js Client Generator generates components for Server Side Rendered applications using [Next.js](https://nextjs.org/).
66

77
## Install
88

9-
### Next + Express Server
9+
The easiest way to get started is to install [the API Platform distribution](../distribution/index.md).
10+
It contains the Client Generator, all dependencies it needs, a Next.js skeleton generated with Create Next App,
11+
a development Docker container to serve the webapp, and all the API Platform components you may need, including an API server
12+
supporting Hydra.
1013

11-
Create a [Next.js application with express server](https://github.com/zeit/next.js/tree/canary/examples/custom-server-express). The easiest way is to execute:
14+
If you use API Platform, jump to the next section!
1215

13-
$ npx create-next-app your-app-name
14-
# or
15-
$ yarn create next-app your-app-name
16+
Alternatively, create a Next.js application by executing:
1617

17-
### Installing the Generator Dependencies
18+
```console
19+
npx create-next-app --typescript your-app-name
20+
# or
21+
yarn create next-app --typescript your-app-name
22+
```
1823

19-
Enable TypeScript in your next project
24+
Install the required dependencies:
2025

21-
yarn add --dev typescript @types/react @types/node
26+
```console
27+
yarn add isomorphic-unfetch formik react-query
28+
```
2229

23-
Install required dependencies:
30+
## Generating Routes
2431

25-
yarn add lodash.get lodash.has @types/lodash isomorphic-unfetch formik
32+
If you use the API Platform distribution, generating all the code you need for a given resource is as simple as running the following command:
2633

27-
## Generating Routes
34+
```console
35+
docker compose exec client \
36+
generate-api-platform-client --resource book -g next
37+
```
38+
39+
Omit the resource flag to generate files for all resource types exposed by the API.
40+
41+
If you don't use the standalone installation, run the following command instead:
2842

29-
$ npx @api-platform/client-generator https://demo.api-platform.com . --generator next --resource book
30-
# Replace the URL by the entrypoint of your Hydra-enabled API
31-
# Omit the resource flag to generate files for all resource types exposed by the API.
43+
```console
44+
npx @api-platform/client-generator https://demo.api-platform.com . --generator next --resource book
45+
# Replace the URL by the entrypoint of your Hydra-enabled API.
46+
# You can also use an OpenAPI documentation with `-f openapi3`.
47+
```
3248

33-
> Note: On the [API Platform distribution](https://github.com/api-platform/api-platform), you can run
34-
> `generate-api-platform-client` instead of `npx @api-platform/client-generator`.
49+
The code has been generated, and is ready to be executed!
3550

3651
## Starting the Project
3752

3853
You can launch the server with
3954

40-
yarn dev
55+
```console
56+
yarn dev
57+
```
4158

4259
Go to `http://localhost:3000/books/` to start using your app.
4360

client-generator/nuxtjs.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ The Nuxt.js Client Generator generates components for Server Side Rendered appli
66

77
### Nuxt
88

9-
Create a [Nuxt.js application](https://nuxtjs.org/guides/get-started/installation#using-create-nuxt-app). The easiest way is to execute:
9+
Create a [Nuxt.js application](https://nuxtjs.org/guides/get-started/installation#using-create-nuxt-app).
10+
The easiest way is to execute:
1011

1112
```console
1213
npx create-nuxt-app your-app-name
@@ -18,7 +19,7 @@ or:
1819
yarn create nuxt-app your-app-name
1920
```
2021

21-
It will ask you some questions you can use these answers :
22+
It will ask you some questions, you can use these answers:
2223

2324
```console
2425
Project name: your-app-name
@@ -41,7 +42,7 @@ yarn add moment lodash vue-i18n vuelidate vuex-map-fields nuxt-i18n
4142
yarn add --dev @nuxtjs/vuetify @nuxtjs/fontawesome
4243
```
4344

44-
## Updating nuxtjs config
45+
## Updating Nuxt Config
4546

4647
Update your `nuxt.config.js` with following:
4748

@@ -54,20 +55,21 @@ Update your `nuxt.config.js` with following:
5455
],
5556
// ...
5657
// to avoid name conflicts in generators
57-
components: false,
58+
components: false,
5859
```
5960

6061
## Generating Routes
6162

6263
```console
6364
npx @api-platform/client-generator https://demo.api-platform.com . --generator nuxt
65+
# You can also use an OpenAPI documentation with `-f openapi3`.
6466
```
6567

66-
Replace the URL by the entrypoint of your Hydra-enabled API
68+
Replace the URL by the entrypoint of your Hydra-enabled API.
6769

6870
**Note:** Omit the resource flag to generate files for all resource types exposed by the API.
6971

70-
## Updating default layout
72+
## Updating Default Layout
7173

7274
Update your `layouts/default.vue` with following:
7375

client-generator/quasar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ In the app directory, generate the files for the resource you want:
1212

1313
```console
1414
npx @api-platform/client-generator https://demo.api-platform.com src/ --generator quasar --resource foo
15+
# You can also use an OpenAPI documentation with `-f openapi3`.
1516
```
1617

1718
Replace the URL by the entrypoint of your Hydra-enabled API.

client-generator/react-native.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
To use this generator you need [Node.js](https://nodejs.org/) and [Yarn](https://yarnpkg.com/) (or [npm](https://www.npmjs.com/)) installed.
88
To run the command line tool, we also recommend using [npx](https://www.npmjs.com/package/npx).
99

10-
Create a React Native application using [Expo CLI](https://docs.expo.io/workflow/expo-cli/).
10+
Create a React Native application using [Expo CLI](https://docs.expo.io/workflow/expo-cli/):
1111

1212
```console
1313
yarn global add expo-cli
@@ -32,6 +32,7 @@ In the app directory, generate the files for the resource you want:
3232

3333
```console
3434
npx @api-platform/client-generator https://demo.api-platform.com . --generator react-native --resource book
35+
# You can also use an OpenAPI documentation with `-f openapi3`.
3536
```
3637

3738
Replace the URL with the entrypoint of your Hydra-enabled API.
@@ -46,15 +47,13 @@ import { Router, Stack } from 'react-native-router-flux';
4647
// Replace "book" with the name of the resource type
4748
import BookRoutes from './routes/book';
4849

49-
const RouterComponent = () => {
50-
return (
51-
<Router>
52-
<Stack key="root">
53-
{BookRoutes}
54-
</Stack>
55-
</Router>
56-
);
57-
};
50+
const RouterComponent = () => (
51+
<Router>
52+
<Stack key="root">
53+
{BookRoutes}
54+
</Stack>
55+
</Router>
56+
);
5857

5958
export default RouterComponent;
6059
```
@@ -94,11 +93,11 @@ export default class App extends Component {
9493
form
9594
}), {}, applyMiddleware(thunk));
9695
return (
97-
<Provider store={store}>
98-
<View style={{flex: 1}}>
99-
<Router/>
100-
</View>
101-
</Provider>
96+
<Provider store={store}>
97+
<View style={{flex: 1}}>
98+
<Router/>
99+
</View>
100+
</Provider>
102101
);
103102
}
104103
}

0 commit comments

Comments
 (0)