Find a file
2023-08-10 10:42:43 -06:00
api Add precommit and basic sqlalchemy setup 2023-08-10 10:42:43 -06:00
app Update to latest code from vercel examples 2023-08-10 10:42:07 -06:00
public Initial commit from Create Next App 2023-05-26 09:10:42 -06:00
.eslintrc.json Initial commit from Create Next App 2023-05-26 09:10:42 -06:00
.gitignore Update to latest code from vercel examples 2023-08-10 10:42:07 -06:00
.pre-commit-config.yaml Add precommit and basic sqlalchemy setup 2023-08-10 10:42:43 -06:00
LICENSE Add MIT license 2023-06-06 08:51:46 -06:00
next.config.js Update to latest code from vercel examples 2023-08-10 10:42:07 -06:00
package-lock.json Add FastApi to work with Nextjs Api routes 2023-05-26 09:35:06 -06:00
package.json Update to latest code from vercel examples 2023-08-10 10:42:07 -06:00
pnpm-lock.yaml Update to latest code from vercel examples 2023-08-10 10:42:07 -06:00
poetry.lock Add precommit and basic sqlalchemy setup 2023-08-10 10:42:43 -06:00
postcss.config.js Initial commit from Create Next App 2023-05-26 09:10:42 -06:00
pyproject.toml Add precommit and basic sqlalchemy setup 2023-08-10 10:42:43 -06:00
README.md Update README.md 2023-08-10 10:41:09 -06:00
tailwind.config.js Initial commit from Create Next App 2023-05-26 09:10:42 -06:00
tsconfig.json Initial commit from Create Next App 2023-05-26 09:10:42 -06:00

Next.js FastAPI Starter

Simple Next.js boilerplate that uses FastAPI as the API backend.


Introduction

This is a hybrid Next.js + Python app that uses Next.js as the frontend and FastAPI as the API backend. One great use case of this is to write Next.js apps that use Python AI libraries on the backend.

How It Works

The Python/FastAPI server is mapped into to Next.js app under /api/.

This is implemented using next.config.js rewrites to map any request to /api/:path* to the FastAPI API, which is hosted in the /api folder.

On localhost, the rewrite will be made to the 127.0.0.1:8000 port, which is where the FastAPI server is running.

In production, the FastAPI server is hosted as Python serverless functions on Vercel.

Demo

https://nextjs-fastapi-starter.vercel.app/

Deploy Your Own

You can clone & deploy it to Vercel with one click:

Deploy with Vercel

Developing Locally

You can clone & create this repo with the following command

npx create-next-app nextjs-fastapi --example "https://github.com/jyapayne/nextjs-fastapi"

Getting Started

First, install the dependencies:

npm install
# or
yarn
# or
pnpm install

Then, run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev

Open http://localhost:3000 with your browser to see the result.

The FastApi server will be running on http://127.0.0.1:8000 – feel free to change the port in package.json (you'll also need to update it in next.config.js).

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!