|
| 1 | +# Next.js Generator |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +The Next.js generator scaffolds components for Server Side Rendered applications using [Next.js](https://nextjs.org/). |
| 6 | + |
| 7 | +## Install |
| 8 | + |
| 9 | +The easiest way to get started is to install [the API Platform distribution](../distribution/index.md). |
| 10 | +It contains 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 and OpenAPI. |
| 13 | + |
| 14 | +If you use API Platform, jump to the next section! |
| 15 | + |
| 16 | +Alternatively, create a Next.js application by executing: |
| 17 | + |
| 18 | +```console |
| 19 | +# using pnpm (recommended) |
| 20 | +pnpm create next-app --typescript |
| 21 | +# or using npm |
| 22 | +npm init next-app --typescript |
| 23 | +# or using yarn |
| 24 | +yarn create next-app --typescript |
| 25 | +``` |
| 26 | + |
| 27 | +Install the required dependencies: |
| 28 | + |
| 29 | +```console |
| 30 | +# using pnpm |
| 31 | +pnpm install isomorphic-unfetch formik react-query |
| 32 | +# or using npm |
| 33 | +npm install isomorphic-unfetch formik react-query |
| 34 | +# or using yarn |
| 35 | +yarn add isomorphic-unfetch formik react-query |
| 36 | +``` |
| 37 | + |
| 38 | +## Generating Routes |
| 39 | + |
| 40 | +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: |
| 41 | + |
| 42 | +```console |
| 43 | +docker compose exec pwa \ |
| 44 | + pnpm create @api-platform/client --resource book -g next |
| 45 | +``` |
| 46 | + |
| 47 | +Omit the resource flag to generate files for all resource types exposed by the API. |
| 48 | + |
| 49 | +If you don't use the standalone installation, run the following command instead: |
| 50 | + |
| 51 | +```console |
| 52 | +# using pnpm |
| 53 | +pnpm create @api-platform/client https://demo.api-platform.com . --generator next --resource book |
| 54 | +# or using npm |
| 55 | +npm init @api-platform/client https://demo.api-platform.com . --generator next --resource book |
| 56 | +# or using yarn |
| 57 | +yarn create @api-platform/client https://demo.api-platform.com . --generator next --resource book |
| 58 | +``` |
| 59 | + |
| 60 | +Replace the URL by the entrypoint of your Hydra-enabled API. |
| 61 | +You can also use an OpenAPI documentation with `-f openapi3`. |
| 62 | + |
| 63 | +The code has been generated, and is ready to be executed! |
| 64 | + |
| 65 | +## Starting the Project |
| 66 | + |
| 67 | +You can launch the server with |
| 68 | + |
| 69 | +```console |
| 70 | +# using pnpm |
| 71 | +pnpm dev |
| 72 | +# or using npm |
| 73 | +npm run dev |
| 74 | +# or using yarn |
| 75 | +yarn dev |
| 76 | +``` |
| 77 | + |
| 78 | +Go to `http://localhost:3000/books/` to start using your app. |
| 79 | + |
| 80 | +## Screenshots |
| 81 | + |
| 82 | + |
| 83 | + |
0 commit comments