|
2 | 2 |
|
3 | 3 | 
|
4 | 4 |
|
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/). |
6 | 6 |
|
7 | 7 | ## Install
|
8 | 8 |
|
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. |
10 | 13 |
|
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! |
12 | 15 |
|
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: |
16 | 17 |
|
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 | +``` |
18 | 23 |
|
19 |
| -Enable TypeScript in your next project |
| 24 | +Install the required dependencies: |
20 | 25 |
|
21 |
| - yarn add --dev typescript @types/react @types/node |
| 26 | +```console |
| 27 | +yarn add isomorphic-unfetch formik react-query |
| 28 | +``` |
22 | 29 |
|
23 |
| -Install required dependencies: |
| 30 | +## Generating Routes |
24 | 31 |
|
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: |
26 | 33 |
|
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: |
28 | 42 |
|
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 | +``` |
32 | 48 |
|
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! |
35 | 50 |
|
36 | 51 | ## Starting the Project
|
37 | 52 |
|
38 | 53 | You can launch the server with
|
39 | 54 |
|
40 |
| - yarn dev |
| 55 | +```console |
| 56 | +yarn dev |
| 57 | +``` |
41 | 58 |
|
42 | 59 | Go to `http://localhost:3000/books/` to start using your app.
|
43 | 60 |
|
|
0 commit comments